I need to add Custom Link In Main Menu Only apply Specific Text. currently i have display menu as category. i want to add link only where to buy menu. please help me & Suggest how can i add menu?

Please See my attached files. enter image description here

Thanks In Advance

  • please check this answer, maybe it's help you: magento.stackexchange.com/questions/206572/… Commented May 7, 2020 at 4:56
  • @FaisalSheikh thanks for reply, but this method is add in last menu, not work in middle menu
    – Gaurav
    Commented May 7, 2020 at 5:09
  • is last 4 link are custom links?
    – Amit Bera
    Commented May 7, 2020 at 6:09
  • @AmitBera (our story,faq,our chaitable work) menus are static block, but where to buy is page link.
    – Gaurav
    Commented Jul 20, 2020 at 4:26

2 Answers 2


If the last 4 links are custom links, then you can those custom links add this using Plugin.

See: http://devdocs.magento.com/guides/v2.3/extension-dev-guide/plugins.html

Create a plugin on class Magento\Theme\Block\Html\Topmenu as the menu is rendered from this class and use before plugin on getHtml().

The menu is rendered from this class and use before plugin on getHtml().

1. create a module.module should have minimum below files:


2: create di.xml where we will define the plugin.

location: app\code{VendorName}{ModuleName}\etc\frontend\di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    <type name="Magento\Theme\Block\Html\Topmenu">
        <plugin name="add_cms_menu" type="{VendorName}{ModuleName}\Plugin\Topmenu" sortOrder="20" />

3. Now create the plugin class where we will add a cms page link to the menu.

public function __construct(
    NodeFactory $nodeFactory,
    \Magento\Cms\Model\PageFactory $pageFactory,
    \Magento\Store\Model\StoreManagerInterface $storeManager,
    \Magento\Framework\UrlInterface $urlBuilder
) {
    $this->nodeFactory = $nodeFactory;
    $this->_pageFactory = $pageFactory;
    $this->_storeManager = $storeManager;
    $this->_urlBuilder = $urlBuilder;
public function beforeGetHtml(
    \Magento\Theme\Block\Html\Topmenu $subject,
    $outermostClass = '',
    $childrenWrapClass = '',
    $limit = 0
) {
    /* Showing  Cms page About us at menu */
    $page = $this->getCmspage('about-us');
    if($page == null){

    $node = $this->nodeFactory->create(
            'data' => [
                'name' => $page->getTitle(),
                'id' => $page->getIdentifier(),
                'url' =>  $this->_urlBuilder->getUrl(null, ['_direct' => $page->getIdentifier()]),
                'has_active' => false,
                'is_active' => false // (expression to determine if menu item is selected or not)
            'idField' => 'id',
            'tree' => $subject->getMenu()->getTree()
protected function getCmspage($identifier){

    $page = $this->_pageFactory->create();
    $pageId = $page->checkIdentifier($identifier, $this->_storeManager->getStore()->getId());

    if (!$pageId) {
        return null;
    if (!$page->load($pageId)) {
        return null;

    if (!$page->getId()) {
        return null;

    return $page;


More detail can found article


copy file from


and put this file in your theme location


Add below <li> structure just after <?php /* @escapeNotVerified */ echo $block->getChildHtml(); ?> line in topmenu.phtml

<li class="level0 level-top ui-menu-item">
    <a href="<?php echo $this->getBaseUrl()."yourlink"; ?>" class="level-top ui-corner-all"  role="menuitem">
        <span><?php echo __("Your Custom Menu")?></span>

And more read link :-

How to add custom link in main menu in Magento 2?

Hope this help you

Thanks ...

  • Hey Mohit thanks for reply, but this method is add in last menu, not work in middle menu.
    – Gaurav
    Commented May 7, 2020 at 5:10
  • I am no sure but try first line add update line <li class="level0 nav-3 level-top ui-menu-item"> Commented May 7, 2020 at 5:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.