I am trying to remove the cart link and icon from the homepage of Magento 2. But making any changes to
Magento_Theme is removing the cart icon from every page, as expected. Is there any way of removing it just from the homepage?
You can do in your custom theme or in the custom module.
Following code is from my custom module. app/code/Anshu/Custom/view/frontend/layout/cms_index_index.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="minicart" remove="true" /> </body> </page>
Here, Anshu is the namespace and Custom is the module name.
Basically, what you need to change in your code is that instead of using the
default.xml, you need to use
You can go through https://devdocs.magento.com/guides/v2.2/frontend-dev-guide/layouts/xml-instructions.html for more information.
If you only need to hide the icon from homepage, you can manage it using the stylesheets by using the below style