Our brands

How To Add Custom Top Links In Header

magento 2-top-links-header

In this post we will show you how to add a contact link in magento 2 top links header.
Firstly, you need to create a CMS page for example you create an “Contact Us” page with identifier as “contacts”
Secondly, link access to contact page http://domain.com/contacts
Thirdly, to add magento 2 top links, you need to add following code in default.xml of your theme
Add code in body tag of a file *.xml. For example: app/design/frontend/Magento/YOUR_THEME/Magento_Theme/layout/default.xml

<?xml version=”1.0″?>
<page xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:noNamespaceSchemaLocation=”urn:magento:framework:View/Layout/etc/page_configuration.xsd”>
<block class=”\Magento\Framework\View\Element\Html\Link” name=”ves-top-link”>
<argument name=”label” xsi:type=”string” translate=”true”>Contact Us1</argument>
<argument name=”path” xsi:type=”string” translate=”true”>contacts</argument>

The previous code will be redirected to “Magento\Framework\View\Element\Html\Link” class and tranfers label = Contact Us and path = contacts(http://domain.com/contacts)
After that, Check the PHP Magento\Framework\View\Element\Html\Link.php file, there is one link shown on frontend

protected function _toHtml()
if(!$this->_helperData->getConfig(‘general/enable’)) return;
$page_title = $this->_helperData->getConfig(‘latest/page_title’);
$route = $this->_helperData->getConfig(‘general/route’);
$link = ‘<li class=”dt-event-toplink”><a href=”‘ . $this->getUrl($route) . ‘”> ‘ . $page_title . ‘ </a></li>’;
return $link;

If you still confuse about this Tutorials, please feel free to contact our professional support team with more than 7 years of experiences for more helpful aid.
All questions are always welcomed. Contact us now! Magento Development Services

Related Magento 2 Extensions and Magento 2 Tutorials

Share this Post!

Alena Dao
Alena Dao
“Good marketing makes the company look smart. Great marketing makes the customer feel smart.”

0 Comment

Leave a Comment

Your email address will not be published.

Do NOT follow this link or you will be banned from the site!