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?
Magento Stack Exchange is a question and answer site for users of the Magento e-Commerce platform. It only takes a minute to sign up.
Sign up to join this communityI 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?
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.