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.
If you want get query string params in controller file,...
Create di.xml and add the below code Magemonkey/Redirect/etc/frontend/di.xml [crayon-628457bf45c2c401767440/] Create...
You can try below code to change local date to...
Step 1: First you need to add registration.php file in...
Step1 : Override message.js in current theme file on the...