Magento 2 Override layout xml

Follow the below steps to override layout xml. Here I am creating a module ‘PHPCodez_Layout’ that will remove header and footer content from the active theme.

Declare Module

File : app/code/PHPCode/Layout/etc/module.xml

<?xml version="1.0"?>
<config xmlns:xsi="" xsi:noNamespaceSchemaLocation="../../../../../lib/internal/Magento/Framework/Module/etc/module.xsd">
 <module name="PHPCodez_Layout" setup_version="0.0.1"/>

Register the module

File : app/code/PHPCodez/Layout/registration.php


Create Layout XML file

File : app\code\PHPcodez\Layout\view\frontend\layout\default.xml

<?xml version="1.0"?>
<page xmlns:xsi="" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
 <referenceContainer name="header.container" remove="true" />
 <referenceContainer name="footer" remove="true" />

Issue the following commands and you can see that header and footer contents are removed from the pages.

php bin/magento setup:upgrade
php bin/magento setup:di:compile
php bin/magento setup:static-content:deploy -f
php bin/magento cache:clean

Leave a Reply

Your email address will not be published. Required fields are marked *