Parent theme (theme design directory path)


Here is the sample code :

<?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">
    <update handle="customheader" /> 

Now, While inside the child theme, I want to do some customization which I have done in the same file.


But it is also taking the content from the parent theme (taking blocks and containers from update handle "customheader"),

I have cross-verified by checking the body tag having "customheader" class for in child theme.

I want to remove the handle "customheader" from my child theme programmatically.

I have tried $layout->getUpdate()->removeHandle('customheader') using observer of layout_load_before but it is not working.

Note: I want to remove the handle programmatically only, I don't want to remove each blocks and container manually.

3 Answers 3


Please try below solution in your child themes xml file. I hope it helps you.

<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
        <referenceRemove name="handler_name_to_remove"/>
  • thanks for the suggestion, but no tag "<referenceRemove" is found in the codebase. Can you please share any references? Commented May 23 at 5:17
  • ok jigar, then its complex to remove in single line code. you have to work either with observer or you have to remove from element from xml which are declared in customheader Commented May 26 at 19:18

You can use observer to manipulate the layout before it is rendered.

Create one observer for the event layout_load_before

In observer, access the layout object. use removeHandle() method to remove the handle you want to remove

Event: app/code/Jigar/CustomModule/etc/frontend/events.xml

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
    <event name="layout_load_before">
        <observer name="remove_custom_handle" instance="Jigar\CustomModule\Observer\RemoveCustomHandle" />

Observer :

namespace Jigar\CustomModule\Observer;

use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

class RemoveCustomHandle implements ObserverInterface
    public function execute(Observer $observer)
         // get layout object from observer
        $layout = $observer->getLayout();
        // remove customheader handle from layout update
  • Thanks for the suggestion, Implemented the same already as described in question, but it is not working. As when i print the handles I'm not getting "customheader" in the list at it is getting added after this event dispatched.Thanks Commented May 22 at 9:13

TLDR, If you can't remove it, Add it

I have found an alternative way,

As a child inherits properties from the parent theme, we can not remove updates directly from the child theme.

So, I have followed a different approach.

I have removed layout handle updates from the parent themes which were previously defined in the particular XML files.

Then I added it thorough observer instead of removing it whenever required.

this way worked as per my requirement.

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.