We sacrifice by not doing any other technology, so that you get the best of Magento.

We sacrifice by not doing any other technology, so that you get the best of Magento.

We have two choices for achieving this functionality.

One option is to directly add in topmenu.phtml by overriding a file in your theme. There are chances that it won’t work if you have a third party mega menu extension.

Another way is by using the plugin, Here we are going to talk about the same.

We can achieve our requirement by executing two steps:

First, you need to create di.xml in your custom module.

[Vendor Name]/[Module Name]/etc/di.xml
<!-- Add custom menu in navigation -->
<type name="MagentoThemeBlockHtmlTopmenu">
    <plugin name="add_registry_inmenu" type="[Vendor Name][Module Name]PluginCustommenu" sortOrder="10" disabled="false"/>
</type>

Now you have to create a plugin file in your custom module

[Vendor Name]/[Module Name]/Plugin/Custommenu.php
<?php

namespace [Vendor Name][Module Name]Plugin;

class Custommenu
{
    public function afterGetHtml(MagentoThemeBlockHtmlTopmenu $menu, $html)
    {
        $giftTopUrl = $menu->getUrl('giftr/search/result'); /* Here is the menu link which are redirect after click */
        $baseUrl = $menu->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
        if (strpos($baseUrl,'giftr/search/result') !== false) {
            $html .= "<li class="level0 nav-5 active level-top parent ui-menu-item">";
        } else {
            $html .= "<li class="level0 nav-4 level-top parent ui-menu-item">";
        }
        $html .= "<a href="" . $giftTopUrl . "" class="level-top ui-corner-all"><span>" . __("Gift Registry") . "</span></a>";
        $html .= "</li>";
        return $html;
    }
}

After executing both steps, run below command:

php bin/magento cache:flush

Now you can check your navigation menu. Your custom menu is added after all top menus.

field_5bfb909c5ccae

    Recent Articles
    Get a Free Quote

      Full Name

      Email Address

      Mobile Number

      Message

      Let’s initiate a discussion!!

      With Only Agency that provides a 24/7 emergency support.

        Full Name

        Email Address

        Mobile Number

        Message