Magento 2 add link customer navigation
Today we discuss about Magento 2 add link customer navigation.This tutorial include how you can add your custom link in customer account navigation, Magento 2 add link customer navigation. So let’s start with our example.
If you are adding it from theme layout then create default.xml in following path.
app/design/frontend/QaisarSatti/theme/Magento_Theme/layout/default.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="test-link">
<arguments>
<argument name="path" xsi:type="string">test/controller/action</argument>
<argument name="label" xsi:type="string">Test Link</argument>
<argument name="sortOrder" xsi:type="number">150</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="test-link">
<arguments>
<argument name="path" xsi:type="string">test/controller/action</argument>
<argument name="label" xsi:type="string">Test Link</argument>
<argument name="sortOrder" xsi:type="number">150</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
Or you want it to add from module layout then create default.xml in following path.
app/code/QaisarSatti/view/HelloWorld/frontend/layout/default.xml
<?xml version="1.0"?>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="test-link">
<arguments>
<argument name="path" xsi:type="string">test/controller/action</argument>
<argument name="label" xsi:type="string">Test Link</argument>
<argument name="sortOrder" xsi:type="number">150</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
<!--
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="customer_account_navigation">
<block class="Magento\Customer\Block\Account\SortLinkInterface" name="test-link">
<arguments>
<argument name="path" xsi:type="string">test/controller/action</argument>
<argument name="label" xsi:type="string">Test Link</argument>
<argument name="sortOrder" xsi:type="number">150</argument>
</arguments>
</block>
</referenceBlock>
</body>
</page>
One thought on “Magento 2 add link customer navigation”
Leave a Reply
You must be logged in to post a comment.
Hello,
I’ve tried to do this solution to add multiple links to the sidebar but it unfortunately doesn’t work. Even when trying to create a new .xml file in the layout directory.
How would create multiple links in the account sidebar?
Thank you.