Step 1: For this, you have to create a small module. In that module, you have to create di.xml on the below path where we will define the plugin.
Path : app\code\Vortex\Cravens\etc\di.xml
You have to add the below code in the di.xml file
1 2 3 4 5 6 |
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Theme\Block\Html\Topmenu"> <plugin name="contact_us_menu" type="Vortex\Cravens\Plugin\Topmenu" sortOrder="1" /> </type> </config> |
Step 2: Create a plugin on the below path and add the below-mentioned code into that file.
Path : app\code\Vortex\Cravens\Plugin\Topmenu.php
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
<?php namespace Vortex\Cravens\Plugin; use Magento\Framework\Data\Tree\NodeFactory; class Topmenu { protected $nodeFactory; protected $_storeManager; protected $_pageFactory; protected $_urlBuilder; 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 ) { $node = $this->nodeFactory->create( [ 'data' => [ 'name' => __('Contact Us'), 'id' => 'contact-us', 'url' => $this->_urlBuilder->getUrl('contact'), 'has_active' => false, 'is_active' => false // (expression to determine if menu item is selected or not) ], 'idField' => 'id', 'tree' => $subject->getMenu()->getTree() ] ); $subject->getMenu()->addChild($node); } } |
By doing these steps the contact us menu will get added in the top menu.
If you want to show the different contents for Mobile...
Please follow the below methods to get the attribute options...
Update product attribute value programmatically in Magento 2 . [crayon-628781b22dc70443502391/]...
If you want restrict customer to checkout based on your...
Sometime we need to set html data without load or...