1

I need to set My account link to be # . It shouldn't redirect anywhere.

There's a possible way to set it as # using plugin in module.

But I want to do it in theme. Is there's a way to achieve in theme?

2
  • Do you need to add "#" for header My accocunt link? – aravind Feb 12 '20 at 8:18
  • Yes you are right @aravind – Haerriz Feb 12 '20 at 9:44
1

It's usually bad practice to use '#' or 'javascript:void()' in href tag. I would not recommend this, instead you can prevent the link from firing with jQuery.

$(document).ready(function() {
    $(".my-account-link").click(function(event) {
        event.preventDefault(); 
    });
});

Instead of using jQuery, I recommend to just change the block with custom template.

If you look into vendor/magento/module-customer/view/frontend/layout/default.xml you can see how Magento creates the link.

<block class="Magento\Customer\Block\Account\Link" name="my-account-link">
    <arguments>
        <argument name="label" xsi:type="string" translate="true">My Account</argument>
        <argument name="sortOrder" xsi:type="number">110</argument>
    </arguments>
</block>

As there is no template directly related to Customer Account link, I would suggest that you remove the default Magento block that handles My Account link.

1) Create the file app/design/frontend/[vendor]/[your-theme]/Magento_Theme/layout/default.xml

2) Add the following:

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column"
      xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="top.links">
            <block class="Magento\Framework\View\Element\Template" name="my-custom-account-link" template="my-account.phtml" before="register-link"/>
        </referenceBlock>
        <!-- remove My Account Link -->
        <referenceBlock name="my-account-link" remove="true"/>
    </body>
</page>

3) Create your custom template in app/design/frontend/[vendor]/[your-theme]/Magento_Theme/templates/my-account.phtml and add your content.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.