How to hide filters from specific category pages
The WooCommerce Product Filters plugin allows you to automatically display filters to the top of all product list pages using either the 'Display above the list of products in your store' setting. However, there are scenarios where you may wish to hide these global filters from specific category pages. For example, you might have a 'Wholesale' category where filters are not required, or a specific landing page category where the layout works better without them.
Since the setting is global, you can use a simple code snippet to programmatically disable the filters on specific category pages while keeping them active everywhere else.
1. Find your category slugs
First, you need to identify the unique "slug" for the categories where you want to hide the filters.
- Log into your WordPress admin.
- Go to Products → Categories.
- In the list of categories, locate the categories you wish to target.
- Look at the Slug column and copy the text exactly as it appears (e.g., hoodies, t-shirts, accessories).
2. Add the code snippet
Next, you need to add a PHP code snippet to your site. You can do this by adding it to your child theme's functions.php file or, preferably, by using a plugin like Code Snippets.
Tip: If you are unsure how to add code to your site, please read our guide on how to use code snippets.
Paste the following code into your snippets plugin or functions file:
PHP
add_action( 'wp', function() {
// List category slugs where you want to disable the filters.
// Replace 'hoodies', 'category-two', etc. with your actual category slugs.
$target_categories = [
'hoodies',
'category-two',
'category-three',
];
// Check if we are on one of the target category pages
if ( is_product_category( $target_categories ) ) {
// Return false to disable the filter components
add_filter( 'wcf_has_components', '__return_false' );
}
});
3. Customize the code
Before saving, you must edit the code to match your specific categories.
In the code above, look for the section labeled $target_categories.
Replace the example slugs ('hoodies', 'category-two', etc.) with the slugs you copied in Step 1. Ensure each slug is wrapped in single quotes ' ' and followed by a comma.
Example: If you want to hide filters only on the 'accessories' category, your code would look like this:
PHP
add_action( 'wp', function() {
$target_categories = [
'accessories',
];
if ( is_product_category( $target_categories ) ) {
add_filter( 'wcf_has_components', '__return_false' );
}
});
Once saved, the filters will no longer appear on those specific category pages.
Troubleshooting
If the filters are still appearing on the category page after adding the code, please check the following:
- Check the slug - Ensure you used the category Slug and not the Name. Slugs are usually lowercase and contain hyphens instead of spaces (e.g., use summer-sale not Summer Sale).
- Clear your cache - If you use a caching plugin (like WP Rocket) or server-side caching, clear the cache after adding the code to ensure the changes take effect.
- Check your display method - This code specifically disables filters added via the global 'Display above the list of products in your store' setting in the plugin options. If you manually added the filters using a shortcode or a widget/block directly onto that page, this code will not hide them. In that case, you should simply edit the page or widget area and remove the filter shortcode/block manually.