How To Remove Menu From Header In Magento 2
Ever tried to remove the main menu from the header in Magento 2? Maybe because you wanted a customized menu instead of the default one. Or you have a one-page website which doesn’t require menu at all. Or the client’s site did not require the menu altogether!
In such cases, you need to remove menu from header in Magento 2 and here’s the programmatic solution to do the same.
For example, you don’t want to distract a user on the checkout page when he is about to make a conversion on your site with a menu that may prompt him to check or browse more.
So, you can simply remove the main menu from the header and speed up the conversion process at the checkout.
Programmatic method to remove menu from header in Magento 2:
Add below code into XML file where you want to remove the navigation menu:
1 2 3 |
<referenceContainer name="header-wrapper"> <referenceBlock name="navigation.sections" remove="true" /> </referenceContainer> |
To remove the main menu from all pages in Magento 2:
Create app\code\[Vendor]\[Module]\frontend\layout\default.xml
1 2 3 4 5 6 7 8 |
<?xml version="1.0"?> <page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd"> <body> <referenceContainer name="header-wrapper"> <referenceBlock name="navigation.sections" remove="true" /> </referenceContainer> </body> </page> |
That’s it.
Any doubts about the topic or the code implementation can be mentioned in the Comments section. I’d be happy to help.
Feel free to share the solution with Magento community via social media.
Thank you.
Sanjay Jethva
Sanjay is the co-founder and CTO of Meetanshi with hands-on expertise with Magento since 2011. He specializes in complex development, integrations, extensions, and customizations. Sanjay is one the top 50 contributor to the Magento community and is recognized by Adobe.
His passion for Magento 2 and Shopify solutions has made him a trusted source for businesses seeking to optimize their online stores. He loves sharing technical solutions related to Magento 2 & Shopify.
Prev
What is Magento – Here’s what you need to know
How To Remove Search From Header In Magento 2
Next