cancel
Showing results for 
Search instead for 
Did you mean: 

How to hide a specific category from the layered navigation filter in Magento 2?

How to hide a specific category from the layered navigation filter in Magento 2?


Hi friends,

I’m using Magento ver. 2.4.5-p12 and I want to hide one specific category from the "Category" filter in the layered navigation on category pages.

I still want this category to exist and be assigned to products (for navigation or organizational purposes), but I don't want it to appear as a filter option in the layered navigation.

In the Display Settings of the category, I only see options like:

  • Hide Filter Attributes on Layered Navigation
  • Available Product Listing Sort By
  • Default Product Listing Sort By
  • Layered Navigation Price Step

There's no Is Anchor option in my version of Magento.


Is there a built-in way to exclude a specific category from the category filter in layered navigation? If not, what would be the best way to achieve this (e.g., via plugin or observer)?


Thanks in advance!

2 REPLIES 2

Re: How to hide a specific category from the layered navigation filter in Magento 2?

Hi @peter_rosinský ,

There are several ways to remove specific categories from the layer navigation in Magento 2.

1) If you prefer using a plugin or .phtml approach, you can refer to the following link:

https://magento.stackexchange.com/questions/149999/magento-2-remove-category-filter-from-list-page-f...

2) Alternatively, you can override the following file:
vendor/magento/module-catalog/Model/Layer/Filter/Category.php

Within the protected function _getItemsData(), you can add your custom logic based on your requirements.

 

Problem Solved? Accept as Solution!

 

Thanks

Ankit

Ankit Jasani

Re: How to hide a specific category from the layered navigation filter in Magento 2?

Hi @peter_rosinský,

You can remove specific categories from Magento 2's layered navigation in a couple of ways:

If you're using a plugin or phtml method, check this solution on Magento StackExchange:
https://magento.stackexchange.com/questions/149999/magento-2-remove-category-filter-from-list-page-f...

Or override this file:
vendor/magento/module-catalog/Model/Layer/Filter/Category.php
Then edit the _getItemsData() method to filter out categories based on your logic.

I had to do something similar for Magis TV — works well for a cleaner layered navigation.

Problem solved? Mark it as the solution.

Thanks!