How can i change or move the link that when i click the (Contact us) in navigation bar the output will be the same in (contact us) in footer?
1 Answer
If you want to add a link to navigation then you need to create a plugin
on Magento\Theme\Block\Html\Topmenu
and use before
plugin on _getHtml()
create di.xml where we will define plugin
app\code{VendorName}{ModuleName}\etc\di.xml
<?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="add_contact_us_menu" type="{VendorName}{ModuleName}\Plugin\Topmenu" sortOrder="1" />
</type>
</config
Now create the plugin class where we will add a contact us page link to menu.
<?php
namespace {VendorName}\{ModuleName}\Plugin;
use Magento\Framework\Data\Tree\NodeFactory;
class Topmenu
{
protected $nodeFactory;
protected $_storeManager;
protected $_urlBuilder;
public function __construct(
NodeFactory $nodeFactory,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\UrlInterface $urlBuilder
) {
$this->nodeFactory = $nodeFactory;
$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-page',
'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);
}
}
More detail get at here
-
I don't want to create a cms i just want to redirect the link of (Contact Us) footer in the (Contact Us) navigation bar. Commented Jun 13, 2018 at 6:16
-
Don't create any cms page. What you want navigation Contact Us redirect to (Contact Us) footer link? Have u already create ` Contact Us` , is this link a category?– Amit Bera ♦Commented Jun 13, 2018 at 6:23
-
The default footer have a contact us cms page. I want that to show when i click the Contact Us navigation bar. Commented Jun 13, 2018 at 6:29
-
if your contact us is a cms page then amitbera.com/magento2-add-a-cms-page-link-to-menu blog will help you– Amit Bera ♦Commented Jun 13, 2018 at 7:23
-