How to Hide a Filter in Specific Category
You can hide and show layered navigation filters in specific categories using layout updates.
Layout XML Files
Since Magento 2.3.4, instead of editing layout XML in the settings of a category page, put layout XML instructions for a category into the app/design/frontend/[theme_vendore]/[theme_name]/Magento_Catalog/layout/catalog_category_view_id_[category_id].xml
file.
In the file itself, wrap XML instruction into <page>
and <body>
XML elements, for example:
<?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="content">
<referenceBlock name="above_products.mana.layered_nav">
<action method="hide">
<argument name="name" xsi:type="string">price</argument>
</action>
</referenceBlock>
</referenceContainer>
</body>
</page>
Examples
To hide price filter in left layered navigation block, add the following to category layout update field:
<referenceContainer name="sidebar.main">
<referenceBlock name="main.mana.layered_nav">
<action method="hide">
<argument name="name" xsi:type="string">price</argument>
</action>
</referenceBlock>
</referenceContainer>
To hide all filters above product list, add the following to category layout update field:
<referenceContainer name="content">
<referenceBlock name="above_products.mana.layered_nav">
<action method="hideAll" />
</referenceBlock>
</referenceContainer>
To show price filter above product list and hide all other filters, add the following to category layout update field:
<referenceContainer name="content">
<referenceBlock name="above_products.mana.layered_nav">
<action method="hideAll" />
<action method="show">
<argument name="name" xsi:type="string">price</argument>
</action>
</referenceBlock>
</referenceContainer>
Specifying Layered Navigation Block
There are up to 4 layered navigation blocks on the page, and in each of them, you can hide and show filters:
In layered navigation in main sidebar:
<referenceContainer name="sidebar.main"> <referenceBlock name="main.mana.layered_nav"> <!-- one or more filter hiding/showing instructions --> </referenceBlock> </referenceContainer>
In layered navigation above products:
<referenceContainer name="content"> <referenceBlock name="above_products.mana.layered_nav"> <!-- one or more filter hiding/showing instructions --> </referenceBlock> </referenceContainer>
In layered navigation displayed on mobile devices:
<referenceContainer name="content"> <referenceBlock name="mobile.mana.layered_nav"> <!-- one or more filter hiding/showing instructions --> </referenceBlock> </referenceContainer>
In layered navigation in additional sidebar:
<referenceContainer name="sidebar.additional"> <referenceBlock name="additional.mana.layered_nav"> <!-- one or more filter hiding/showing instructions --> </referenceBlock> </referenceContainer>
Hide/Show Instructions
Hiding specified filter:
<action method="hide">
<argument name="name" xsi:type="string">attribute_code</argument>
</action>
Hiding all filters:
<action method="hideAll" />
Showing specified filter:
<action method="show">
<argument name="name" xsi:type="string">attribute_code</argument>
</action>
Showing all filters:
<action method="showAll" />
Hiding/Showing Filters In List Of Applied Filters
In addition to hiding filters from layered navigation, you may also hide applied filter from list of applied filters which typically appears at the top of layered navigation block.
Hiding specified filter:
<action method="hideAppliedFilter">
<argument name="name" xsi:type="string">attribute_code</argument>
</action>
Hiding all filters:
<action method="hideAllAppliedFilters" />
Showing specified filter:
<action method="showAppliedFilter">
<argument name="name" xsi:type="string">attribute_code</argument>
</action>
Showing all filters:
<action method="showAllAppliedFilters" />