
Magento 2.x – Add new top link and remove existing one using xml
If you want to do some changes on the top links of your store, such as adding new ones, or removing default ones, you will need to have your own theme, and, regardless of that, it will depend if it inherits from Luma or Blank, as follows:
If you extended Luma Theme:
app/design/frontend/<vendor>/<theme>/Magento_Theme/layout/default.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <!-- you can easly add New links with following code --> <referenceBlock name="header.links"> <!-- Contact us Link --> <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link" after="register-link"> <arguments> <argument name="label" xsi:type="string" translate="false">Constact Us</argument> <argument name="path" xsi:type="string" translate="false">contact-us</argument> </arguments> </block> <!-- CMS Page Link --> <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link"> <arguments> <argument name="label" xsi:type="string" translate="false">about Us</argument> <argument name="path" xsi:type="string" translate="false">about-us</argument> </arguments> </block> <!-- you can easly Remove links with following code --> <referenceBlock name="register-link" remove="true" /> <!--for Create Account Link--> <referenceBlock name="authorization-link" remove="true" /> <!--for Sign In Link --> <referenceBlock name="wish-list-link" remove="true" /> <!--for WishList Link--> <referenceBlock name="my-account-link" remove="true" /> <!--for My Account Link--> </referenceBlock> </body> </page> |
If you extended Blank Theme:
app/design/frontend/<vendor>/<theme>/Magento_Theme/layout/default.xml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <!-- you can easly add New links with following code --> <referenceBlock name="top.links"> <!-- Contact us Link --> <block class="Magento\Framework\View\Element\Html\Link" name="contactus.link" after="register-link"> <arguments> <argument name="label" xsi:type="string" translate="false">Constact Us</argument> <argument name="path" xsi:type="string" translate="false">contact-us</argument> </arguments> </block> <!-- CMS Page Link --> <block class="Magento\Framework\View\Element\Html\Link" name="aboutus.link" after="contactus.link"> <arguments> <argument name="label" xsi:type="string" translate="false">about Us</argument> <argument name="path" xsi:type="string" translate="false">about-us</argument> </arguments> </block> <!-- you can easly Remove links with following code --> <referenceBlock name="register-link" remove="true" /> <!--for Create Account Link--> <referenceBlock name="authorization-link" remove="true" /> <!--for Sign In Link --> <referenceBlock name="wish-list-link" remove="true" /> <!--for WishList Link--> <referenceBlock name="my-account-link" remove="true" /> <!--for My Account Link--> </referenceBlock> </body> </page> |