My Account display only after login

My Account display only after login

August 14, 2026 · Illustrated author avatarBy Stefan Bogdanescu
My Account display only after login

If you’re looking to change the default top links in Magento and display only the “My Account” link after users have logged in, you’ve come to the right place. In this post, we’ll walk through the process of modifying these links using a combination of Magento’s built-in features and some custom code.

By default, Magento displays the following top links:

  • My Account
  • My Wishlist
  • My Cart
  • Checkout
  • Log in

These links are part of the store’s header layout and are controlled by the Magento_Theme module. The main file responsible for rendering these links is located at vendor/magento/module-theme/view/frontend/templates/html top.phtml.

Before we dive into custom code, let’s see what Magento offers out of the box.

  1. Disable/Enable Certain Links: You can disable individual links using the admin interface. Go to Stores > Configuration > Sales > Checkout and enable/disable each link as needed.

  2. Change Link Names: Although not mentioned in your question, you can change the name of these links from the admin panel as well. Go to Stores > Configuration > General > Design and find the “Header Links” configuration option.

To achieve the desired behavior—displaying only “My Account” after login—we’ll need to add some custom logic.

  1. Create a New Layout File

First, create a new layout XML file in your theme or module. Let’s call it top_links.xml and place it under the app/design/frontend/{vendor}/{theme}/Magento_Theme/layout directory.

<!-- app/design/frontend/{vendor}/{theme}/Magento_Theme/layout/top_links.xml -->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:App/etclayouts.xsd">
    <body>
        <referenceBlock name="top.links">
            <arguments>
                <argument name="class" xsi:type="string">Magento\Theme\Block\Html\Toplinks</argument>
                <argument name="template" xsi:type="string">vendor_module/top.phtml</argument>
            </arguments>
        </referenceBlock>
    </body>
</page>
  1. Create the Custom PHTML File

Next, create a new PHTML file called top.phtml in the following directory: app/design/frontend/{vendor}/{theme}/Magento_Theme/templates/vendor_module.

<!-- app/design/frontend/{vendor}/{theme}/Magento_Theme/templates/vendor_module/top.phtml -->
<div class="header-links">
    <?php if ($this->helper('Magento\Customer\Helper\Session')->isLoggedIn()): ?>
        <span class="top-link my-account">
            <a href="<?= $block->getUrl('customer/account/') ?>" title="<?= $block->escapeHtml(__('My Account')) ?>">
                <?= $block->escapeHtml(__('My Account')) ?>
            </a>
        </span>
    <?php endif; ?>
</div>
  1. Check for Logged-In Status

In the PHTML file, we’re using Magento’s customer session helper to check if a user is logged in. If they are, we display the “My Account” link.

Conclusion

Customizing top links in Magento requires a combination of admin configurations and custom programming. We’ve shown you how to disable/enable links through the admin interface and created a custom PHTML file that displays only the “My Account” link after users have logged in.

Remember, when working with core files or creating custom modules, always follow best practices to ensure your changes are sustainable in future updates.

For more advanced customizations and tips on Magento development, be sure to check out our blog at https://laravelcompany.com/blog/tag/magento. We cover a wide range of topics from theme development to backend customization.

Checkout Extensions Themes Admin

Our network