Magento 2 - Making categories in Layered Navigation link, instead of filter

Magento 2 - Making categories in Layered Navigation link, instead of filter

August 4, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento 2 - Making categories in Layered Navigation link, instead of filter

Magento 2: Making Layered Navigation Categories Link Instead of Filter

Layered navigation is a powerful tool for enhancing user experience by allowing customers to filter products based on categories. However, there are situations where you might want the layered navigation links to direct users to the category page rather than filtering product results.

Let’s explore how to achieve this in Magento 2, using the following category structure as an example:

- Lamps
    -- Hanging lamps
    -- Wall lamps
    -- Floor lamps

Understanding the Layered Navigation Behavior

By default, when you click on a subcategory in the layered navigation menu, Magento filters the product listing to display only the products belonging to that specific category. This is the intended behavior for most e-commerce stores.

However, if your store’s requirements dictate that clicking on a subcategory should take users directly to its category page rather than filtering results, you’ll need to make some adjustments.

Setting Up the Category Structure

First, ensure that your categories are set up correctly in Magento. Go to ‘Catalog -> Categories’ and configure each category:

  • Give each subcategory (Hanging lamps, Wall lamps, Floor lamps) a URL key and enable the ‘Is Active’ status.
  • Set the parent category (Lamps) as a root category with no parent.

To change the behavior of layered navigation links, you need to modify the Magento code. This involves editing core files, which can potentially cause issues if not done correctly. It’s recommended to create a child theme or copy necessary files to your custom theme folder before making changes.

Editing the Layered Navigation Block

  1. Navigate to app/code/Magento/LayeredNavigation/Block/Item.php in your Magento installation.
  2. Open the file and look for the function getIsActive().
public function getIsActive()
{
    return $this->categoryId === $this->currentCategory->getId();
}

This function determines whether a category is active based on the current filter.

Modifying the Active Criteria

To make the subcategories link instead of filter, you need to change the active criteria. Replace the existing getIsActive() function with this updated version:

public function getIsActive()
{
    if ($this->categoryId === $this->currentCategory->getId()) {
        return 'active';
    } elseif ($this->currentCategory->isSubOf($this->category)) {
        return '';
    }

    return 'inactive';
}

In this updated version, we’re checking if the current category is a subcategory of the filtered one. If it is, the link will simply open the corresponding category page without filtering.

Testing the Changes

After making these changes:

  1. Clear the cache: bin/magento cache:clean.
  2. Verify that clicking on subcategories in the layered navigation now directs users to the respective category pages rather than filtering product listings.

For more detailed guidance on customizing Magento 2 themes and understanding its architecture, I recommend exploring Laravel Company’s comprehensive guide. This article provides a solid foundation for working with Magento’s filesystem and theme structure.

Conclusion

Making layered navigation links in Magento 2 direct to the category page instead of filtering products requires modifying core files. By updating the getIsActive() function in the LayeredNavigation/Block/Item.php file, you can achieve this behavior while keeping your store’s codebase neat and organized.

It’s essential to remember that working with Magento’s core files should be done carefully, ideally by creating child themes or maintaining separate customization files. This ensures that your changes don’t conflict with future updates or patches.

If you find yourself needing more advanced customizations for layered navigation, Magento 2 offers a robust platform for extending its functionality using plugins and observers. For detailed tutorials on these topics, visit Laravel Company’s Magento resource center.

Happy coding! Let me know if you have any further questions or need assistance with other Magento development tasks.

Magento 2 Catalog Configuration Customers

Our network