How to Exclude Category from WordPress Homepage

WordPress shows content from all categories on the homepage by default...

WordPress shows content from all categories on the homepage by default. However, sometimes, it is inappropriate. Specifically, the issue occurs when some blog categories are undesirable to show in the default WordPress cycle, such as on the site’s homepage.

There are several reasons for this. However, you can exclude category from homepage with a bit of modification to your WordPress theme’s functions.php file.

To do this, you must thus know the ID of a particular page. Down the required (or rather unneeded to show) category IDs and eliminate them from the homepage display. And here, we’ll demonstrate how to do it. Be attentive to details!

Why Exclude a Category from WordPress Homepage?

WordPress allows you to sort content into categories and tags. Sometimes, you may want to use a category for posts that are not part of your regular blog entries.

WordPress doesn’t have default settings to allow you to hide posts in specific categories from the homepage or archives. Unfortunately, this leaves you with unwanted posts appearing on your homepage.

Let’s see how you can easily exclude a specific category from your WordPress homepage. We will show you two different methods, and you can choose the one that best fits your need.

Exclude Category from WordPress Homepage Using Code

This approach involves adding code to WordPress files. You must add the following code to the functions.php file of your theme or a site-specific plugin.

Excluding Single Category from WordPress Homepage

Use the following code to exclude a single category from your WordPress homepage.

Category ID
Category ID
function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-1' );
}
return $query;
}

add_filter( 'pre_get_posts', 'exclude_category_home' );

Replace ID (-1) with the ID of your category. It will exclude any blog articles corresponding to the category with this ID from the homepage. Remember to include a minus sign (-) with the category ID.

Functions.php
Functions.php

Then, just paste it into your theme’s functions.php file.

Excluding Multiple Categories from WordPress Homepage

If you want to exclude multiple categories, modify the code as follows:

function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-1, -2, -3' );
}
return $query;
}

add_filter( 'pre_get_posts', 'exclude_category_home' );

Then, just paste it into your theme’s functions.php file.

Replace the IDs (-1, -2, -3) with the IDs of the categories you want to exclude from your WordPress homepage.

Exclude Category from WordPress Homepage Using Plugins

If coding foes over your head, there is another easy way to exclude a category. You can use plugins to do that. As you know, WordPress is promoting Gutenberg, a block-based builder, so there are now varieties of plugins available on the market. 

One of the best Gutenberg block-based plugins is PostX, which we will use to show you how to exclude categories from the WordPress homepage.

So, without further ado, let’s get started.

  • To use PostX, you need to first install it. 

👉🏼Do check our guide on installing plugins!

  • Then go to WordPress Dashboard.
  • Next, go to pages, and select a page or create a new one.
Selecting Grid
Selecting Grid
  • Take a grid, i.e., Post Grid#1
Query Setting
Query Settings
  • Go to Settings from the right sidebar.
  • Navigate to the Query setting.
Excluding Category
Excluding Category
  • Scroll down a bit till you see Exclude Term.
  • Select the category or categories you want to exclude.
  • Update or publish.

And you’re done. Easy peasy lemon squeezy!

There are other ways of Removing Categories. Do Check them Out:
How to Remove Category from URL in WordPress
How to Add a Category and Subcategory in WordPress
How to Add Featured Image to Category in WordPress
How to Create WordPress Custom Category Page Template Without Coding

Conclusion

Due to the unpredictability of our needs, the website and, more specifically homepage may sometimes require a little redesign. This article demonstrates how to exclude category from WordPress homepage.

If you still have any concerns, please comment below. We will be happy to help you out with any WordPress related issues.

Editorial Staff
Editorial Staff

With over 10+ years of experience in the industry, our experts from the editorial panel are a trusted source of knowledge for WordPress solutions. As part of the editorial staff at WPLearners, our experts are dedicated to sharing their expertise and helping you make the most of your WordPress journey.

Leave a Reply