How to remove compare link on Magento2 header

How to remove compare link on Magento2 header

To remove the compare link from the header in Magento 2, you can follow these steps: First, create a custom module if you haven’t already. Inside your module, create a di.xml file under app/code/[Vendor]/[Module]/etc/frontend/ and use the Magento\Catalog\Block\Product\Compare\Link block class to remove the compare link. You can achieve this by adding the following code to your di.xml file:

<type name="Magento\Catalog\Block\Product\Compare\Link">
<arguments>
<argument name="template" xsi:type="string">Magento_Catalog::empty.phtml</argument>
</arguments>
</type>
This code will effectively remove the compare link from the header by overriding its template with an empty file. After that, clear the Magento cache using the command php bin/magento cache:clean. This will ensure that the changes take effect, removing the compare link from your store’s header.