Magento provides flexibility to update page designs as per business requirements to improve customer experience. As a part of this, we may be required to remove blocks or containers from specific layout files in Magento.
In Magento 2 layouts, you can easily remove a specific block or container using the magical “remove” attribute.
You can use referenceBlock for the blocks, and referenceContainer for the containers.
Syntax :
<referenceBlock name="your.block.name" remove="true"/>
<referenceContainer name="your.container.name" remove="true"/>
Suppose there is a requirement to remove footer links from all the pages.
The footer links come from the block “footer_links“, so we can specify below the line in the default.xml if we want to remove footer links from all pages.
<referenceBlock name="footer_links" remove="true"/>
above code will remove footer links from the footer. If you want to remove a specific footer link you can specify those using the block name of the links as shown below.
<?xml version="1.0"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceBlock name="contact-us-link" remove="true"/>
<referenceBlock name="catalog-search-advanced-link" remove="true"/>
</body>
</page>
You may also like :
How to use ifconfig in layout xml Magento 2?
That’s it for this tutorial, See you in the next blog. Happy Coding 🙂
Leave a Comment