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.
[crayon-63d98579316ff573463532/] 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.