How To Add Top Link In Magento 2

In this post, I will guide you on How To Add Top Link In Magento 2. Use the header of the website to deploy advertising campaigns, gratitude for the store’s customers.

The header of the website is the location that attracts a lot of attention, this is an ideal place to place important events, promotional campaigns, shopping, gratitude for your customers. Adding a link at the top of the page will make it easier for customers to reach it.

The difference between header and top link is:

  • The header is visible to both guests and logged in.
  • The top link is only visible to logged in customers.

Steps To Add Top Link In Magento 2

1. Create default.xml file in the following path:

app\code\{your-Vendor}\{your-Extension}\view\frontend\layout\default.xml

2. And add the following code:

<?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">
<body>
      <referenceBlock name="header.links">
        <block class="Magento\Framework\View\Element\Html\Link" name="top-link">
          <arguments>
              <argument name="label" xsi:type="string" translate="true">Top Link Label </argument>
              <argument name="path" xsi:type="string" translate="true">url_path</argument>
          </arguments>
        </block>
      </referenceBlock>
</body>
</page>

You substitute the values below according to your need:

  • Top Link Label: The label of the top link you want to add to your store.
  • url_path: The URL path for the top link.

3. Then, run deploy static content, flush cache command and see the result:

php bin/magento setup:static-content:deploy -f
php bin/magento cache:flush

Follow us for the more helpful posts!

We hope this is a useful post for you.

You can read more useful posts like How To Change Order Increment ID Length In Magento 2.

Thank you for reading!

4.8 4 votes
Article Rating

Aaron LX

Aaron is a passionate writer, crazy about shopping, eCommerce and trends. Besides his outstanding research skills and a positive mind, Aaron eagerly shares his experience with the readers.

Leave a Reply or put your Question here

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x