Hiding Magento Breadcrumbs for Specific Pages
Breadcrumbs are an essential part of any e-commerce website’s navigation structure. They help users understand their current location within your store and provide easy access to higher levels in the hierarchy. However, there may be instances where you want to hide these breadcrumbs for specific pages.
In this post, we’ll walk through how to remove or hide breadcrumbs on a single page using Magento 2. This is particularly useful for advanced search results pages or any other custom-built page within your store.
Understanding the Default Breadcrumbs in Magento
By default, Magento uses the breadcrumbs layout handle to render breadcrumbs across all pages. It’s defined in the catalogsearch_result_index.xml layout file:
<referenceContainer name="content">
<block class="Magento\Theme\Block\Html\Breadcrumbs" before="-" name="breadcrumbs"/>
</referenceContainer>
Here, the Magento\Theme\Block\Html\Breadcrumbs block is added to the content area of the page.
Removing Breadcrumbs from a Specific Page
To hide breadcrumbs on a specific page like the search result page, you need to override this layout XML in your theme or custom module. Follow these steps:
-
Create a new layout file in your theme or module:
vendor/magento/theme-frontend-blank/Magento_Theme/page_layout/search_result.xml -
Add the following content to override the breadcrumbs block for the search result page:
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
<update handle="catalogsearch_result_index"/>
<referenceContainer name="content">
<referenceBlock name="breadcrumbs" remove="true"/>
</referenceContainer>
</page>
In this XML, the remove attribute is set to true for the breadcrumbs block. This tells Magento not to render the breadcrumbs block on the search result page.
Verifying the Changes
To verify that your changes have taken effect:
-
Enable the developer mode in Magento (if you haven’t already):
bin/magento deploy:mode:set developer -
Clear the cache:
bin/magento cache:clean -
Navigate to your search results page after conducting a search.
You should find that the breadcrumbs are now completely removed from this specific page, providing a cleaner layout and better focus on the search results themselves.
Conclusion
Hiding or removing Magento breadcrumbs for specific pages is a straightforward process involving layout XML overrides. By following the steps outlined above, you can easily customize your store’s navigation to fit your unique business needs.
Remember that this approach applies to the default Magento installation. If you’re using third-party modules or themes, the layout file structure may vary slightly. Always refer to the documentation provided by those vendors for specific instructions.
For more advanced customizations and a deeper dive into Magento development, I recommend exploring the extensive resources available at Laravel Company. They offer comprehensive guides and tutorials covering everything from basic setup to complex extensions.