How to set active menu links under 'My Account' in Magento 2 frontend Customer Section

How to set active menu links under 'My Account' in Magento 2 frontend Customer Section

August 17, 2026 · Illustrated author avatarBy Stefan Bogdanescu
How to set active menu links under 'My Account' in Magento 2 frontend Customer Section

Making Custom Menu Links Active in Magento 2 Customer Section

As you’re building your custom module for the customer account section in Magento 2, you’ve encountered an issue with maintaining active menu links across parent and child pages. The ‘My Uploads’ link under ‘My Account’ is bolded and active on the index page, but this functionality doesn’t carry over to the child pages within the same section.

Let’s dive into how we can keep the same link as active throughout your custom module’s menu structure.

Understanding Magento 2 Menu Active State Handling

In Magento 2, the active state for menu items is typically handled by the _isActive method in controllers. This method checks if the current page matches the URL defined for the menu item.

However, you’re correct that _setActiveMenu is an admin controller method and isn’t directly accessible from frontend controllers. To achieve your desired functionality without using this method, we’ll need to manually set the active state within our custom module’s layout XML file.

Setting Active Menu State in Layout XML

Create a new layout XML file under app/design/frontend/<your_vendor>/<your_theme>/Magento_Theme/layout/default.xml. Add the following code inside the <referenceBlock name="customer_account_navigation"> block:

<action method="setActive">
    <argument name="menu_id" xsi:type="string">custom_uploads</argument>
    <argument name="active" xsi:type="boolean">true</argument>
</action>

Replace custom_uploads with the unique identifier for your custom menu item.

Updating Your Custom Menu Item

Ensure that your custom menu item has a unique identifier in its configuration. If you’re using a layout XML file to define your menu items (like app/design/frontend/<your_vendor>/<your_theme>/Magento_Theme/layout/customer_account_menu.xml), you should have something like this:

<referenceBlock name="customer_account_navigation">
    <block class="Magento\Framework\View\Element\Html\Link" name="custom_uploads_link">
        <arguments>
            <argument name="label" xsi:type="string" translate="true">My Uploads</argument>
            <argument name="path" xsi:type="string">customer/uploads/index</argument>
            <argument name="id" xsi:type="string">customer-uploads-menu-item</argument>
            <argument name="class" xsi:type="string">active menu-item</argument>
        </arguments>
    </block>
</referenceBlock>

The id argument should match the menu_id we used in our layout XML file.

Finalizing Your Solution

Save your changes and clear the cache by running:

php bin/magento cache:flush

Now, when a customer navigates to any page within ‘My Account’, your custom ‘My Uploads’ link should remain bolded and active as they move between different pages in the section.

Conclusion

In this blog post, we explored how to maintain active menu links across parent and child pages for custom modules extending the Magento 2 customer account section. By manually setting the active state using layout XML files and ensuring your custom menu item has a unique identifier, you can achieve consistent link behavior throughout your customized ‘My Account’ sidebar.

Remember that proper configuration of unique identifiers is crucial to ensure the correct links are targeted by your layout modifications.

For more advanced customization techniques and best practices in Magento 2 development, consider exploring our comprehensive guides at Laravel Company.

Magento 2 Indexing Extensions Themes

Our network