Hide certain Magento attribute filters

Hide certain Magento attribute filters

August 29, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Hide certain Magento attribute filters

Hiding Certain Magento Attribute Filters: Simplifying Layered Navigation

As an experienced Magento developer, I often encounter scenarios where clients want to customize their layered navigation block to hide specific attribute filters without manually listing them out. In this post, we’ll explore a more efficient way to achieve this by modifying the existing PHP code to automatically hide all filter attributes except for “Price” and “Category”.

The Current Approach: Manually Hiding Filters

The provided PHP code snippet demonstrates the current approach of hiding filters:

<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
    <?php if($_filter->getItemsCount()): ?>
        <?php if($_filter->getName() != "Price" AND $_filter->getName() != "Category"): ?>
            <dt><?php echo $this->__($_filter->getName()) ?></dt>
            <dd><?php echo $_filter->getHtml() ?></dd>
        <?php endif; ?>
    <?php endif; ?>
<?php endforeach; ?>

However, this approach requires you to manually list out all the attribute filters that you don’t want to show by adding them to the condition. This becomes time-consuming and impractical as your catalog grows.

A More Efficient Solution: Automatically Hiding Non-Price/Category Filters

To achieve an automatic solution where only “Price” and “Category” filters are displayed, we need to modify the PHP code. Here’s how you can do it:

<?php $_filters = $this->getFilters() ?>
<?php foreach ($_filters as $_filter): ?>
    <?php if($_filter->getItemsCount()): ?>
        <dt><?php echo $this->__($_filter->getName()) ?></dt>
        <dd><?php echo $_filter->getHtml() ?></dd>
    <?php endif; ?>
<?php endforeach; ?>

In this optimized version, we’ve removed the condition that checks for “Price” and “Category” filters. This means that by default, all filter attributes will be displayed.

Ensuring Price and Category Filters Are Always Shown

To ensure that “Price” and “Category” filters are always shown regardless of any other filters being present, you need to modify your Magento theme’s layered navigation template file located at:

app/design/frontend/[Your Theme]/template/catalog/layer/view.phtml

Find the following code segment within this file:

<?php $_filters = $this->getFilters() ?>
...

Add the condition back in and adjust it like this:

<?php if($_filter->getName() == "Price" OR $_filter->getName() == "Category"): ?>
    <dt><?php echo $this->__($_filter->getName()) ?></dt>
    <dd><?php echo $_filter->getHtml() ?></dd>
<?php endif; ?>

This ensures that only the “Price” and “Category” filters are shown, while all other filter attributes are automatically hidden.

Conclusion: Streamlining Magento Layered Navigation

By implementing this optimized approach, you can simplify your layered navigation management process. You no longer need to manually list out the filters you want to hide; instead, they will be automatically excluded, leaving only “Price” and “Category” filters visible.

This solution provides a cleaner, more maintainable codebase that scales better as your catalog grows. It demonstrates how small modifications in Magento’s core templates can lead to significant improvements in user experience and site performance.

Remember, it’s always important to test these changes thoroughly before deploying them to your live production environment. If you’re unsure about any aspect of this process, don’t hesitate to reach out to our team at Laravel Company for expert guidance on Magento development and customization.

Happy coding!

Catalog Pricing CLI

Our network