How To Remove Search From Header In Magento 2 Programmatically

Method to remove search from the header in Magento 2

To remove the search from all the pages paste the following code in the default.xml.

Directory

app/code/VendorName/ModuleName/frontend/layout/default.xml

Content of default.xml

<?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.container">
<referenceBlock name="top.search" remove="true"/>
</referenceContainer>
</body>
</page>

To remove the search from the specific page paste the following code in the, for example, if you want to remove the search from the checkout success page.

Directory

app/code/VendorName/ModuleName/frontend/layout/checkout_onepage_success.xml

Content of checkout_onepage_success.xml

<?xml version="1.0"?>
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" layout="1column" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<body>
<referenceContainer name="header.container">
<referenceBlock name="top.search" remove="true"/>
</referenceContainer>
</body>
</page>
If you are looking for Magento Developers, visit Magento Developer Agency.
Related Products