🔥 Just Launched! Werra Premium Template for HyväSee it in Action

How to Dynamically Add Link to Customer Account Navigation in Magento 2

By Sanjay JethvaUpdated on Jul 16, 2025 2 min read

Magento 2 eCommerce CMS allows customizing the default features based on the business requirements. Magento offers a rule-based condition field using which the admin can easily configure the condition-based features.

While creating a navigation link on my account dashboard, you need to create a customer file as static. But, at times, you need to change it to dynamic. This is not possible in default Magento.

For an instance, in Multi-vendor extension, there are multiple types of sellers such as retailers, wholesalers, general. So, every customer group requires different functionalities that might be unnecessary for others. Custom options are needed for the sellers to add a new product. In such a case, it displays such options to sellers only. Whereas, for the customers, such an option is not visible.

However, you can easily create a custom link dynamically using the code provided here. I have provided a complete solution to dynamically add link to customer account navigation in Magento 2 below.

Method to Dynamically Add Link to Customer Account Navigation in Magento 2:

Create customer_account.xml file under app/code/Vendor/Module/view/frontend/layout

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Vendor\Module\Block\Customer\DynamicLink" name="customer-navigation-dynamic-link" after="-">
                <arguments>
                    <argument name="label" xsi:type="string">Dynamic Link</argument>
                    <argument name="path" xsi:type="string">customer/dynamicLink/index</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

Create DynamicLink.php file under app/code/Vendor/Module/Block/Customer/

<?php
namespace Vendor\Module\Block\Customer;

use Magento\Framework\View\Element\Html\Link\Current;
use Magento\Framework\View\Element\Template\Context;
use Magento\Framework\App\DefaultPathInterface;
use Magento\Customer\Model\Session;

class DynamicLink extends Current
{
    protected $customerSession;

    public function __construct(
        Context $context,
        DefaultPathInterface $defaultPath,
        Session $customerSession,
        array $data = []
     ) {
         $this->customerSession = $customerSession;
         parent::__construct($context, $defaultPath, $data);
     }

    protected function _toHtml()
    {    
        $responseHtml = null;
        if($this->customerSession->isLoggedIn()) {
                // here you can put your custom conditions
                $responseHtml = parent::_toHtml();
        }
        return $responseHtml;
    }
}

That’s it.

Also, I’d be grateful if you could share the solution with the Magento community via social media.

Thank you.

Sanjay Jethva Full Image
Article bySanjay Jethva

Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe. His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.