1

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?

2 Answers 2

5

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

2
  • this will remove link / block from all cms pages, isn't so ? Commented Oct 23, 2018 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. Commented Oct 23, 2018 at 11:11
1

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;}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.