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 : appcodeVortexCravensetcdi.xml
You have to add the below code in the di.xml file
<?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="MagentoThemeBlockHtmlTopmenu">
<plugin name="contact_us_menu" type="VortexCravensPluginTopmenu" sortOrder="1" />
</type>
</config>
Step 2: Create a plugin on the below path and add the below-mentioned code into that file.
Path : appcodeVortexCravensPluginTopmenu.php
Code:
<?php
namespace VortexCravensPlugin;
use MagentoFrameworkDataTreeNodeFactory;
class Topmenu
{
protected $nodeFactory;
protected $_storeManager;
protected $_pageFactory;
protected $_urlBuilder;
public function __construct(
NodeFactory $nodeFactory,
MagentoCmsModelPageFactory $pageFactory,
MagentoStoreModelStoreManagerInterface $storeManager,
MagentoFrameworkUrlInterface $urlBuilder
) {
$this->nodeFactory = $nodeFactory;
$this->_pageFactory = $pageFactory;
$this->_storeManager = $storeManager;
$this->_urlBuilder = $urlBuilder;
}
public function beforeGetHtml(
MagentoThemeBlockHtmlTopmenu $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.

