How to Remove a Block from Layout in Magento2?

In the Magento architecture, a "Block" is one of the first class elements in the structure of Magento layouts. Every page in Magento is decorated by the "Layouts" file and the content is filled up by the "Blocks" of the different modules. Magento blocks are a really powerful and flexible way to plug­ your content into the already existing layouts. On the other hand, you could also use layout XML files to easily remove or reposition any existing blocks.

In Magento 2, you can suppress the display of a block using the remove tag.

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

 Here 'block_name' is your own block name which you want to remove from the layout.

For Example:

<?xml version="1.0"?>
<page layout="1column" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:noNamespaceSchemaLocation="../../../../../../../lib/internal/Magento/Framework/View/Layout/etc/page_configuration.xsd">
    <body>
        <referenceBlock name="navigation.sections" remove="true"/>
    </body>
</page>

Using the above example you can remove the default navigation section from the layout.

 If you face any problems or need our professional services, please email us at [email protected]

Join our Newsletter

Never miss the latest offers, voucher codes and useful articles delivered weekly in your inbox.