Magento 2 add custom link top links
Today, we’ll talk about how in Magento 2 add custom link top links.It is very create For any suggestions & question, please feel free to drop a comment.
If you are adding it from theme create default.xml in following path.
app/design/frontend/QaisarSatti/theme/Magento_Theme/layout/default.xml
Or you want it to add from module xml then create default.xml in following path.
app/code/QaisarSatti/view/HelloWorld/frontend/layout/default.xml
Blank Theme top links
Now add the following code, you can add label and url as you required.
<referenceBlock name="top.links">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="cart" before="account">
<arguments>
<argument name="label" xsi:type="string">Cart</argument>
<argument name="path" xsi:type="string">checkout/cart</argument>
</arguments>
</block>
</referenceBlock>
<block class="Magento\Framework\View\Element\Html\Link\Current" name="cart" before="account">
<arguments>
<argument name="label" xsi:type="string">Cart</argument>
<argument name="path" xsi:type="string">checkout/cart</argument>
</arguments>
</block>
</referenceBlock>
Luma Theme header links
Now add the following code, you can add label and url as you required.
<referenceBlock name="header.links">
<block class="Magento\Framework\View\Element\Html\Link\Current" name="cart" before="account">
<arguments>
<argument name="label" xsi:type="string">Cart</argument>
<argument name="path" xsi:type="string">checkout/cart</argument>
</arguments>
</block>
</referenceBlock>
<block class="Magento\Framework\View\Element\Html\Link\Current" name="cart" before="account">
<arguments>
<argument name="label" xsi:type="string">Cart</argument>
<argument name="path" xsi:type="string">checkout/cart</argument>
</arguments>
</block>
</referenceBlock>
2 thoughts on “Magento 2 add custom link top links”
Leave a Reply
You must be logged in to post a comment.
very useful
working 100%