Question

In Magento 2 how can I remove a link from top.links via layout? I am assuming you can do this because every link is block in the top.links node is a its own block.

This is was a question I had earlier today. Because there is little information on this I will answer my own question and hopefully this will be of help for other people.

Was it helpful?

Solution

Lets say if you want to remove the sign in link. You first need to find out the parent block, then create a conditional action (using the ifconfig attribute) to unset a child block and then pass the alias/name of the child block as an argument.

<referenceBlock name="top.links">
    <action method="unsetChild" ifconfig="section_id/group/enabled">
        <argument name="alias" xsi:type="string">authorization-link</argument>
    </action>
</referenceBlock>

Note: ifconfig only accepts true or false (1/0) and will only unset the child if the value is true.

Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange
scroll top