We want to remove Magento's default main navigation using xml file but don't want to use remove, because ifconfig not working with remove.

We want to remove main navigation only when our custom module is disabled.

We have tried below codes but it's not working.

// CODE 1
<referenceContainer name="store.menu">
    <action method="unsetChild" ifconfig="rootmegamenu_option/general/enable">
        <argument name="alias" xsi:type="string">catalog.topnav</argument>

// CODE 2
<referenceContainer name="store.menu">
     <action method="unsetChild"><child>catalog.topnav</child></action>

// CODE 3
<referenceContainer name="store.menu">
     <action method="unsetChild" ><name>catalog.topnav</name></action>

Help will be appreciated.

3 Answers 3


This is a very late response, but I just managed to do this by adding the following to my default.xml file:

<referenceBlock name="navigation.sections" display="false" />

I found out the element name by looking around in /vendor/magento/module-theme/view/frontend/layout/default.xml.


If you want to remove the navigation, without the navigation section. You could also implement it by putting the following line in any .xml file preferably the default.xml to apply it everywhere.

<referenceBlock name="catalog.topnav" remove="true"/>

When the entire navigation section has to be removed the following line can be used.

<referenceBlock name="navigation.sections" remove="true"/>
  1. Refer this link to check module staus
  2. Follow the below instructions to remove the item programmatically

    if ($this->moduleManager->isOutputEnabled('Vendor_Module')) {
        $layout = $this->getLayout();
        $block = $layout->getBlock('Block Name'); // block name
        $layout->unsetElement('Block Name');
    } else {
        //the module output is disabled

I hope it helps!

  • Thank you Bilal Usean but we want to do this from xml file only. Is there any way to do this from XML file? Commented Dec 25, 2017 at 7:27

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.