I am trying to remove the cart link and icon from the homepage of Magento 2. But making any changes to default.xml of 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">
        <referenceBlock name="minicart" remove="true" />

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 cms_index_index.xml

You can go through https://devdocs.magento.com/guides/v2.2/frontend-dev-guide/layouts/xml-instructions.html for more information.

| improve this answer | |
  • this will remove link / block from all cms pages, isn't so ? – Naveed Asim Oct 23 '18 at 11:06
  • @NaveedAsim No, it is will remove only for homepage. cms_index_index.xml is used for home page only. cms_page_view.xml is used for other cms pages. – Anshu Mishra Oct 23 '18 at 11:11

If you only need to hide the icon from homepage, you can manage it using the stylesheets by using the below style

.cms-home .minicart-wrapper{display:none;}
| improve this answer | |

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.