I want to remove the color and price filter only for the specific category in Magento 2.4.3-p1.

I created a separate XML file (catalog_category_view_id_{category_id}.xml) and apply the below code.

 <?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">
       <referenceContainer name="sidebar.main">
           <referenceBlock name="catalog.leftnav">
               <action method="hide">
                   <argument name="name" xsi:type="string">price</argument>
               <action method="hide">
                   <argument name="name" xsi:type="string">color</argument>

I get the below error.

1 exception(s):
Exception #0 (Magento\Framework\Exception\LocalizedException): Invalid method Magento\LayeredNavigation\Block\Navigation::hide

Any help would be appreciated.

Thanks in advance.

  • Do you want to do this using the admin site? Commented Aug 19, 2022 at 7:03
  • @MuhammadMuizAther No, I want to remove it from the frontend side only. Commented Aug 19, 2022 at 7:04
  • I guess that you have an issue with the collection call. Maybe you need to do indexing. Commented Aug 19, 2022 at 7:17
  • 1
    @MuhammadMuizAther Appreciate your comment. It's not related to the collection. It's a simple category with products but I need only selected filters for one category. Hope it's clear now. Thank you Commented Aug 19, 2022 at 7:20
  • 1
    I would add some logic in the filter template directly.. if category name =='' then hide color.. All this with a viewModel is the recommended way but not compulsory Commented Aug 19, 2022 at 7:22

1 Answer 1


the template for rendering the filters is: vendor/magento/module-layered-navigation/view/frontend/templates/layer/filter.phtml (as you know)

In this template, we can see a viewModel /** @var \Magento\LayeredNavigation\ViewModel\Layer\Filter $viewModel */

You could create a preference for this viewModel and add some custom logic that would check if the category can display color or not. This logic could be:

  • comparing category name to a list of names coming from your config
  • if the number of filter items is lower than 2 for instance, then hide the filter

I do believe you were looking at a setting in XML or in the backend and I do not believe there is anything like this

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.