Magento 2, a powerful and flexible e-commerce platform, offers store owners extensive control over the shopping experience. One of the key areas of customization is the layered navigation system, which allows customers to refine product lists by attributes like price, color, and category. However, in certain store designs or specific catalog sections, the category filter can become redundant, confusing, or even detrimental to user experience. For instance, when a user is already browsing within a specific category, showing a category filter for that same category or its siblings can clutter the interface. Removing this filter requires a clear understanding of Magento 2’s layout and block structure. This comprehensive guide will walk you through multiple proven methods to remove the category filter from the layered navigation on your Magento 2 list pages, ensuring a cleaner and more focused shopping journey for your customers.
The decision to remove the category filter is often driven by both aesthetic and functional considerations. A streamlined filter list can reduce cognitive load for shoppers, guiding them more effectively towards other important product attributes like size, material, or brand. Furthermore, on pages where the category context is already strongly established—such as through breadcrumbs or a prominent page title—the category filter adds little value and only consumes valuable screen real estate. By carefully removing it, you can create a more intuitive navigation path, potentially increasing engagement and conversion rates.
Before proceeding with any modifications, it is a cardinal rule of Magento development to back up your site’s files and database. Direct edits to core files should be avoided at all costs; instead, the correct approach involves overriding or extending functionality through your custom theme or module. This practice ensures that your changes remain safe during platform upgrades and that you maintain a stable, manageable codebase. We will focus on methods that adhere to Magento 2 best practices, primarily using layout XML updates and observer-based techniques that are both safe and effective.
Understanding Magento 2’s Layered Navigation Structure
To effectively modify the layered navigation, one must first understand its components. In Magento 2, layered navigation is rendered by a block class typically named Magento\LayeredNavigation\Block\Navigation. This block gathers all available filterable attributes for the current product collection and displays them as a list. Each filter, including the category filter, is an instance of a filter block. The category filter is specifically handled by the Magento\CatalogSearch\Model\Layer\Filter\Category class. It appears in the navigation because it is included in the list of filterable attributes for the catalog layer.
The presentation of these filters is controlled by layout XML files. The key file for category and catalog pages is catalog_category_view.xml. For search results, the corresponding file is catalogsearch_result_index.xml. These files define the structure of the page and specify which blocks are rendered and where. To remove a specific filter, we need to target its block instance within this layout structure and either remove it entirely or prevent it from being rendered. This understanding forms the foundation for all the practical methods we will explore.
Method 1: Removing the Category Filter via Layout XML (Recommended)
This is the most straightforward and commonly recommended method. It involves creating or modifying a layout XML file in your custom theme to remove the category filter block from the layered navigation. This approach is clean, declarative, and easily reversible.
First, you need to locate or create the appropriate layout XML file in your theme. The path within your theme will mirror Magento’s core layout structure.
- Navigate to Your Theme Directory: Go to
app/design/frontend/[YourVendor]/[YourTheme]/. - Create the Necessary Layout File: You will likely need to create the
Magento_Cataloglayout folder and thecatalog_category_view.xmlfile. The full path should be:app/design/frontend/[YourVendor]/[YourTheme]/Magento_Catalog/layout/catalog_category_view.xml. - Add the XML Code: Insert the following code into the newly created file. This code targets the
catalog.leftnavblock and removes the child block responsible for rendering the category filter.
<?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> <referenceBlock name="catalog.leftnav"> <referenceBlock name="category_filter" remove="true"/> </referenceBlock> </body> </page>
For search results pages, you would create a similar file at app/design/frontend/[YourVendor]/[YourTheme]/Magento_CatalogSearch/layout/catalogsearch_result_index.xml with identical content.
After saving the file, clear the Magento cache (bin/magento cache:clean) and refresh your category page. The category filter should now be absent from the layered navigation sidebar.
Method 2: Using a Plugin to Modify Filter List
If you need more programmatic control—for instance, to conditionally remove the filter based on specific rules—using a plugin (interceptor) is a powerful alternative. This method involves creating a simple module that intercepts the method responsible for getting the filters and removes the category filter from the list before it is passed to the frontend block.
This approach is more advanced but offers greater flexibility. You could, for example, create logic to remove the category filter only for certain store views, customer groups, or specific parent categories. To implement this, you need to create a custom module.
- Create the Module Structure: Set up the basic module directories under
app/code/[YourVendor]/[YourModuleName]. - Create the
registration.phpandetc/module.xmlfiles to register your module with Magento. - Create the Plugin Class: The plugin will target the
Magento\Catalog\Model\Layerclass and itsgetStateFiltersmethod (or a similar method that returns the filter collection). A simplified example of the di.xml and plugin class is shown below.
First, create the etc/frontend/di.xml file:
<?xml version="1.0"?> <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd"> <type name="Magento\Catalog\Model\Layer"> <plugin name="remove_category_filter" type="YourVendor\YourModuleName\Plugin\Catalog\Model\Layer" /> </type> </config>
Then, create the plugin class at app/code/[YourVendor]/[YourModuleName]/Plugin/Catalog/Model/Layer.php:
<?php namespace YourVendor\YourModuleName\Plugin\Catalog\Model\Layer;
class Layer
{
public function afterGetStateFilters(\Magento\Catalog\Model\Layer $subject, $filters)
{
$result = [];
foreach ($filters as $filter) {
// Check if the filter is an instance of the category filter
if (!($filter instanceof \Magento\CatalogSearch\Model\Layer\Filter\Category)) {
$result[] = $filter;
}
}
return $result;
}
}
This plugin checks each filter in the list. If a filter is an instance of the category filter class, it is skipped and not added to the result array. After creating the module, run bin/magento setup:upgrade and compile the code (bin/magento setup:di:compile) if necessary, then clear the cache.
Method 3: Overriding the Block Template (Less Advisable)
A third method, though less elegant and not generally recommended as a best practice, involves overriding the layered navigation block’s template file and modifying the PHP logic to exclude the category filter. This method is mentioned for completeness but should be a last resort as it mixes presentation logic with business logic and can be harder to maintain.
You would copy the core template file, typically vendor/magento/module-layered-navigation/view/frontend/templates/layer/view.phtml, to your theme at app/design/frontend/[YourVendor]/[YourTheme]/Magento_LayeredNavigation/templates/layer/view.phtml. Within this file, you would find the loop that renders each filter and add a conditional statement to skip rendering when the filter is a category filter. This requires identifying the filter by its filter model or a unique property.
The main drawback of this method is that it only affects the display. The filter object itself is still loaded and processed, which means this method is less efficient than the previous two, which prevent the filter from being instantiated at all. It also makes your theme more fragile, as changes to the core template in future Magento updates may not be reflected in your override.
Verification and Troubleshooting
After applying any of these methods, it is crucial to verify that the change works correctly and doesn’t introduce side effects.
- Clear All Caches: Always clear the Magento cache (
bin/magento cache:clean), static content cache in your browser, and any full-page cache (Varnish, Cloudflare, etc.) you might be using. - Check Different Pages: Verify the category filter is gone on category pages, search result pages, and advanced search result pages if applicable. If you used the XML method only for categories, it will still appear on search pages unless you apply the same change there.
- Inspect Other Filters: Ensure no other filters have been accidentally affected. All other attribute filters (price, color, etc.) should remain visible and functional.
- Check URL Parameters: Sometimes, a category filter parameter (
cat=...) might be present in URLs from old links or bookmarks. Ensure your site handles these gracefully, either by ignoring the parameter or redirecting to a clean URL, to avoid potential 404 errors or confusion.
If the filter persists, double-check your file paths and names for typos. Ensure your custom theme is correctly applied to the store view you are testing. For the plugin method, verify that the module is enabled (bin/magento module:status) and that no other plugins or configurations are conflicting with it.
Pro Tips for Advanced Management
Beyond simply removing the filter, consider these expert strategies for managing layered navigation more effectively.
- Conditional Removal with Observers or Plugins: Instead of removing the filter globally, use a plugin with sophisticated logic. For example, you could remove the category filter only for logged-in users, only on sale categories, or only when a specific other filter (like brand) is applied. This requires more development skill but creates a dynamic, intelligent user interface.
- Prioritize Other Filters: After removing the category filter, the order of the remaining filters becomes more important. You can control the sort order of filters in the Magento Admin by setting the “Position” attribute of product attributes (Stores > Attributes > Product). Assign lower position numbers (e.g., 10, 20) to the most important filters like Price, Brand, or Size to ensure they appear at the top.
- Consider Mobile Usability: On mobile devices, layered navigation is often implemented as a sliding drawer or modal. Removing a filter like “Category” can simplify this mobile interface significantly, improving touch navigation. Always test your changes on multiple device sizes.
- Monitor Analytics: After making the change, use tools like Google Analytics or Hotjar to monitor user behavior. Look at metrics like bounce rate on category pages, time on page, and conversion funnel progression. This data will tell you if the streamlined navigation is helping or hindering your sales goals.
- Use a Layered Navigation Extension: If you find yourself needing complex filter management, hiding filters for specific categories, or creating custom filter types, investing in a reputable Magento 2 layered navigation extension from the marketplace can be more cost-effective than extensive custom development. These extensions often include granular control over which filters are shown and where.
- Keep Core Code Pristine: Never edit files directly in the
vendor/magento/directory. Any changes there will be overwritten during the next update, causing your site to break. Always use the theme or module override system as demonstrated in this guide.
Frequently Asked Questions
Will removing the category filter affect my site’s SEO?
Generally, no. The category filter is an internal navigation element for users already on your site. Search engines like Google primarily index the canonical category page URLs, not the filtered state URLs (e.g., URLs with ?cat=... parameters). In fact, removing superfluous filters can help prevent the creation of duplicate content or thin content pages that might arise from many filtered states. However, ensure your site’s main category hierarchy is well-structured and accessible via your main navigation menu and sitemap.
Can I remove the filter only from certain categories?
Yes, but it requires a more customized approach. The layout XML method applies globally. To achieve category-specific removal, you would need to use a plugin (Method 2) and within its logic, check the current category ID. You can retrieve the current category from the layer or the registry and then compare its ID against a list of IDs where you want the filter hidden. This involves more advanced PHP coding within your custom module.
The filter is gone, but the “Category” label still appears. Why?
This is unlikely with the methods described, as they remove the filter object entirely. If you see a stray label, it might be coming from a different block or a custom template override in your theme. Inspect the page HTML source to identify the parent container of the label and trace it back to its block name in the layout. You may need to adjust your layout XML to target a different block.
What if I’m using a third-party theme?
The same principles apply. However, your third-party theme may have its own layered navigation structure or template overrides. First, check if your theme already has a catalog_category_view.xml file. If it does, you should add the <referenceBlock name="category_filter" remove="true"/> directive to that existing file rather than creating a new one from scratch, to avoid conflicts. Always test in a development environment first.
Can I rename or reorder the category filter instead of removing it?
Yes. Renaming the filter label is done through translation files or by overriding the filter’s frontend label in the attribute management section. Reordering is done by changing the “Position” value of the “Category” attribute in the product attribute list in the admin panel, similar to other filters.
After an upgrade, my custom change stopped working. What should I do?
Magento upgrades can sometimes overwrite theme files or change core class methods. First, check if the upgrade changed the core file you were overriding or the method your plugin intercepts. Compare your custom files with the new base files from the Magento release. You may need to update your XML layout handles, plugin method names, or template overrides to be compatible with the new version. This underscores the importance of using version control and testing upgrades in a staging environment.
Conclusion
Removing the category filter from the layered navigation in Magento 2 is a strategic customization that can significantly enhance the usability and clarity of your online storefront. Whether your goal is to reduce visual clutter on deep category pages, prevent redundancy, or guide users more effectively towards other product attributes, the process is straightforward when you understand Magento’s layout system. The recommended method for most developers is the layout XML update, as it is clean, declarative, and easy to manage. For more dynamic, condition-based requirements, creating a custom plugin offers the necessary flexibility. By following the step-by-step instructions and best practices outlined in this guide—such as always working within a custom theme or module and thoroughly testing changes—you can confidently implement this modification. Remember to consider the broader context of your store’s navigation strategy, prioritize remaining filters, and monitor user behavior post-implementation to ensure the change delivers the intended improvement to the customer experience.










