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.
1 |
[Vendor Name]/[Module Name]/etc/di.xml |
1 2 3 4 |
<!-- Add custom menu in navigation --> <type name="Magento\Theme\Block\Html\Topmenu"> <plugin name="add_registry_inmenu" type="[Vendor Name]\[Module Name]\Plugin\Custommenu" sortOrder="10" disabled="false"/> </type> |
Now you have to create a plugin file in your custom module
1 |
[Vendor Name]/[Module Name]/Plugin/Custommenu.php |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
<?php namespace [Vendor Name]\[Module Name]\Plugin; class Custommenu { public function afterGetHtml(\Magento\Theme\Block\Html\Topmenu $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:
1 |
php bin/magento cache:flush |
Now you can check your navigation menu. Your custom menu is added after all top menus.
[crayon-63d6869e94f84138476387/] Using above fucntion Images can be imported directly from...
Override view block using di.xml and add the below code...
You can check a list of called layout XML for...
Follow the below steps to install and set up PWA...
If you want to remove all leading zero's from order,...
Let our Magento expert connect to discuss your requirement.
We offer Magento
certified developers.
Our Magento clientele
is 500+.
We sign NDA for the
security of your projects.
We’ve performed 100+
Magento migration projects.
Free quotation
on your project.
Three months warranty on
code developed by us.