Web designers looking over wireframes for new site

How to Exclude a Category From a WordPress Page

Categories are the best way to quickly organize content on your WordPress website. Users can easily find exactly what they’re looking for just by moving through the categories at the top of your page. That said, having too many categories can be overwhelming and even confusing for site users.

That’s why it’s important to display only the most important categories on your homepage.

You may have opted for a site design that only allows for a few categories, or maybe there’s a category you want to use internally but not show publicly.

There’s no native way to exclude a category in WordPress, but in this tutorial, we’ll walk through how to exclude a category in a few simple steps. Here’s what we’ll cover:


Why Exclude a Category?

If your site has been around for awhile, you probably have a lot of content to sift through. But even if your website is just getting started, categories can provide a helpful way to make sense of your content.

You likely won’t have room on your homepage to display all of your categories, so it’s important to hide the ones you don’t need. This greatly helps with user experience by making it faster for users to get where they need to go, as well as speeding up your site (because it’s loading less content).

Improved User Experience

The main function of categories is site navigation. If you have too many categories or redundant ones, visitors might have a hard time finding what they want, get frustrated, and leave.

This is especially important for people using site readers. They could get stuck in a category they don’t need or want and not be able to find the article they were looking for.

Consolidating those categories takes the guesswork away from your site users and presents them with a clear path for finding the content they want.

Improved Page Experience

Not only will your site visitors thank you for the improved navigation, but they’ll also enjoy improved site speed, as removing anything from a page makes it faster to load.

If you have categories you only use internally, such as “Archives,” excluding them from your homepage will allow you to keep using category functionality without dragging down your site.

Now that you know why you might want to exclude a category, let’s look into how to do it. The process is quick and easy.


How to Exclude a WordPress Category

We’ve gone through the why, let’s dive into the how. There are a couple ways to exclude a category from displaying on your WordPress site, but as is often the case when adding needed functionality to your WordPress site, the easiest way is with a plugin.

Use a Plugin

There are a few plugins that are great for excluding a category but we recommend Ultimate Category Excluder. As the name implies, it is a quick and easy way to exclude categories from displaying on your WordPress site.

Here’s how to use it.

Step 1– In your WordPress Admin, go to the Plugin tab in the lefthand toolbar and select “Add New.”

"add New" in the Plugins tab of WordPress Admin

Step 2– Search for Ultimate Category Excluder in the Search tab in the upper right.

Add Plugin search page

Step 3– Select the “Install Now” button and wait for the plugin to install. Then choose the “Activate” button.

Install now and Activate via WordPress Add Plugins

Step 4– Open the plugin and simply check off the categories you would like to exclude and from where. The plugin is very customizable, allowing you to choose between “Main Page,” “Feeds,” “Archives,” and “Search.”

Ultimate Category Excluder Options screen
Quality WordPress plugins such as Ultimate Category Excluder make it easy to exclude categories from your WordPress site.

In addition to Ultimate Category Excluder, there are other well-designed plugins that can help you exclude categories from your WordPress site. Search for all of your options in the WordPress Plugin Repository, just remember to do your due diligence and make sure the plugins you’re evaluating have been recently updated/include positive user reviews.


Use Code

If you don’t want to download another plugin, you can exclude categories from your WordPress site using code. It only takes a few steps and even a WordPress beginner can do it. Step 1– First and foremost, you’ll have to find the page ID for the category you want to exclude. To find this, click on the “Posts” tab in your Admin sidebar and choose “Categories.”

WP Admin "Categories" screen

Then, simply hover over the category you want to exclude. The ID will display in the URL at the bottom after “category&tag_ID=”. For example the ID for the “Events” category would be 29.

Step 2– Now you can add the following code to your functions.php file in your theme. Put your category ID in (‘cat’, ‘-’ ) section.

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-29' );
}
return $query;
}
 
add_filter( 'pre_get_posts', 'exclude_category_home' );

If you want to exclude multiple categories, separate them with a comma like this, ( ‘cat’, ‘-29, -4, -2’ ).

If you decide to include a category again or exclude another, this can be changed at any time.


Conclusion

Excluding a category from a WordPress page can help increase user experience and site speed. If you find your site visitors struggling with site navigation, it can be a really easy way to help them get where they need to go, quickly.

Whether you decide to download a plugin or update your theme code, both of these easy fixes will have your homepage looking cleaner in no time!

Find out more about industry-leading WordPress hosting, including award-winning 24/7/365 support at WP Engine.

Get started.

Build faster, protect your brand, and grow your business with a WordPress platform built to power remarkable online experiences.