Magepow Blog
0
  • Design
  • Ecommerce
  • Featured
  • Magento News
  • Post
  • SEO
  • Technnical

Archives

  • December 2022
  • November 2022
  • October 2022
  • September 2022
  • August 2022
  • July 2022
  • June 2022
  • May 2022
  • April 2022
  • March 2022
  • February 2022
  • January 2022
  • December 2021
  • November 2021
  • October 2021
  • September 2021
  • August 2021
  • July 2021
  • June 2021
  • May 2021
  • April 2021
  • March 2021

Categories

  • Design
  • Ecommerce
  • Featured
  • Magento News
  • Post
  • SEO
  • Technnical

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org
Magepow Blog
Magepow Blog
Magepow Blog
  • Magento 2 Extensions
  • Services
  • Hosting
  • Pricing
  • Support
  • All Articles
0
Magepow Blog
  • Magento 2 Extensions
  • Services
  • Hosting
  • Pricing
  • Support
  • All Articles
0
Magepow Blog > Blog > Post > Magento 2 Add Custom Link Trong My Account Page
Post

Magento 2 Add Custom Link Trong My Account Page

Benjamin Vu
Posted by Benjamin Vu June 30, 2021
0 Shares
READ NEXT
Extensions that should be on a website.

Hello friends. For those who need to add a new link to the sidebar of my account, Magento offers a flexible and simple solution.

By default, this menu is initially declared at 

vendor/magento/module-customer/view/frontend/layout/customer_account.xml

<block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-address-link">
    <arguments>
        <argument name="label" xsi:type="string" translate="true">Address Book</argument>
        <argument name="path" xsi:type="string">customer/address</argument>
        <argument name="sortOrder" xsi:type="number">190</argument>
    </arguments>
</block>

class=”Magento\Customer\Block\Account\SortLinkInterface” here provided by Magento
name=”customer-account-navigation-address-link”, with the name we can customize according to our purpose
argument name =”label” displays the label for the link
argument name=” path” is the path of the link
argument name=”sortOrder” arranges the order of the links before and after, note that Magento arranges in order of DESC, number of The higher sort order will be at the top.

Now let’s create our customer link.
declare customer_account.xml in module Magepow/YourModule/view/frontend/layout/customer_account.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">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-account-new-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">The New Link</argument>
                    <argument name="path" xsi:type="string">router/demo</argument>
                    <argument name="sortOrder" xsi:type="number">10</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

That’s it. You can use the second way, which is to use the declaration in the theme.
app/design/frontend/your_vendor_name/your_theme_name/Magento_Customer/layout/customer_account.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">
    <body>
        <referenceBlock name="customer_account_navigation">
            <block class="Magento\Customer\Block\Account\SortLinkInterface" name="customer-account-navigation-account-new-link">
                <arguments>
                    <argument name="label" xsi:type="string" translate="true">The New Link</argument>
                    <argument name="path" xsi:type="string">router/demo</argument>
                    <argument name="sortOrder" xsi:type="number">10</argument>
                </arguments>
            </block>
        </referenceBlock>
    </body>
</page>

We hope that this article will be helpful to you.

Thanks for reading!

Tags: account link Magento 2

What’s your reaction?

Love
0
Sad
0
Happy
0
Sleepy
0
Angry
0
Dead
0
Wink
0
0 Shares
Share on Facebook Share on Twitter Share on Pinterest Share on Email
Benjamin Vu June 30, 2021
Previous Article speed-up-image-website Add content to Order View Magento 2
Next Article Magento 2 how to configure Nginx to allow execute other PHP files

Leave a Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Follow Socials

Facebook like

Top Reviews

Extensions that should be on a website.

December 30, 2022

How to get image and background in Shopify by Liquid

December 1, 2022

How to install CentOS7 using WSL in Windows 11?

November 30, 2022

YOU MIGHT ALSO LIKE

Extensions that should be on a website.

Posted by Zoe Trinh Zoe Trinh December 30, 2022

How to get image and background in Shopify by Liquid

Posted by Zoe Trinh Zoe Trinh December 1, 2022

How to install CentOS7 using WSL in Windows 11?

Posted by Peter Ngo Peter Ngo November 30, 2022

Guide to translating the language for themes in Shopify.

Posted by Zoe Trinh Zoe Trinh November 28, 2022
  • Design
  • Ecommerce
  • Featured
  • Magento News
  • Post
  • SEO
  • Technnical

Copyright © 2014-2022 Magepow. All rights reserved.