Remove blocks or containers from a layout in Magento 2

Posted on: July 22, 2019
Blog Frontend Magento

Here’s a quick example of how to remove a block or a container called by the layout files, via XML. It’s a simple and quick way to remove items from the page in Magento 2 and can be a very handy way to enhance a Users Experience.

Let’s get started. If you don’t already have the following file:

/app/design/frontend/aware/default/Magento_Theme/layout/default.xml

Go ahead and make it in your theme.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">    
<body>
</body>
</page>

Now inside of this file, add the following line inside of your <body> tags:

<referenceBlock name="your_block_selector" remove="true" />

In this example, I’ve shown how you can remove a Block from the layout, however, the same principle can be achieved with referenceContainer. By replacing the referenceBlock at the start with referenceContainer.

Time to flush the cache and the block or container you wanted to remove will be gone.

Summary

Hopefully, this little tutorial will help you achieve a quick and easy route to removing unused blocks or containers on your Magento 2 page.

Here at aware, we create bespoke eCommerce websites that convert and drive sales. With bespoke theme’s built just for you. Get in touch.

8 Ways to Use Video Marketing to Increase Your eCommerce Sales
8 Ways to Use Video Marketing to Increase Your eCommerce Sales
Posted on: October 11, 2019

While it’s true that high-quality product images, carefully crafted descriptions and glowing reviews all play a critical role in successful ecommerce, there’s something else that can really help boost your sales… Video marketing. As…

Read more
Magento 1 End of Life: Everything You Need to Know
Magento 1 End of Life: Everything You Need to Know
Posted on: October 10, 2019

Last year it was announced that Magento 1 will reach ‘end of life’ in June 2020. Although websites running on Magento 1.x will still continue to function and be accessible after this date, they…

Read more
Legal requirements for an eCommerce site
Legal requirements for an eCommerce site
Posted on: September 19, 2019

As the owner of a website, you have a legal obligation to make sure that your site fully complies with all current legislation. Legal requirements apply to businesses of all sizes, from the tiniest…

Read more