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:
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!
Solved! Go to Solution.
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!
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:
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
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!
I was facing the same issue to add my upcoming new custom product. Finally landed at the right thread and got my solution.