i want to add a page in menu. How can i create it?
Please help me!
Simply above link talking to add the simple sort code in your topmenu.phtml
. So You go to your topmenu.phtml
file and put the some code
<li class="level0 nav-8 last level-top ui-menu-item" role="presentation"><a href="yoururl" class="level-top ui-corner-all" id="ui-id-9" tabindex="-1" role="menuitem"><span>A TITLE</span></a></li>
After your,
delete all files in `var/view_preprocessing`
php bin/magento c:c
php bin/magento c:f
And see the output
Hope this help you
Thanks ...
Need to create custom module.
In app/code/{{vendor}}/{{modulename}}/etc/di.xml - add following code.
<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<!-- Add Plugin for add custom link in navigation -->
<type name="Magento\Theme\Block\Html\Topmenu">
<plugin name="add_menu_item_plugin" type="<vendor>\<modulename>\Plugin\TopmenuAfterPlugin" sortOrder="10" disabled="false"/>
</type>
</config>
Now create TopmenuAfterPlugin.php file here app/code/{{vendor}}/{{modulename}}/Plugin folder with following code.
<?php
namespace {{vendor}}\{{modulename}}\Plugin;
class TopmenuAfterPlugin
{
public function afterGetHtml(\Magento\Theme\Block\Html\Topmenu $topmenu, $html)
{
$customUrl = $topmenu->getUrl('testmenu/menu');//here you can set link
$magentoCurrentUrl = $topmenu->getUrl('*/*/*', ['_current' => true, '_use_rewrite' => true]);
if (strpos($magentoCurrentUrl,'testmenu/menu') !== 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=\"" . $customUrl . "\" class=\"level-top ui-corner-all\"><span class=\"ui-menu-icon ui-icon ui-icon-carat-1-e\"></span><span>" . __("Custom Menu") . "</span></a>";
$html .= "</li>";
return $html;
}
}