Beginner's Guide for WordPress / Start your WordPress Blog in minutes

How to Exclude a Category From Your WordPress Homepage

Do you want to exclude a specific category from your website’s homepage? By default, WordPress displays posts from all categories on your homepage. In some cases, you may not want that. In this article, we will show you how to easily exclude a category from your WordPress homepage.

Exclude Category from WordPress Homepage

Why Exclude a Category from WordPress Homepage?

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

By default, WordPress does not allow you to hide posts in specific categories from homepage or archives. This leaves you with unwanted posts appearing on your homepage.

That being said, 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.

Method 1: Exclude a Category from WordPress Using Plugin

First thing you need to do is to install and activate the Ultimate Category Excluder plugin. For more details, you should follow our guide on how to install a WordPress plugin.

Upon activation, you’ll need to go to Settings » Category Excluder page. It will display all the categories that are available on your WordPress blog.

Category excluder settings

From here, you can simply check one or multiple categories under the ‘Exclude from front page’ column. If you want, then you can also exclude the category from RSS feeds, archives, or even from WordPress search.

Exclude category

Don’t forget to click on the Update button to store these settings.

Now you can visit your website to see that the posts from the selected categories are excluded from the front page.

Method 2: Exclude a Category from WordPress Homepage Using Code

This method requires you to add code to your WordPress files. If you haven’t done this before, then see our guide on how to copy and paste code snippets in WordPress.

You will need to add following code to your theme’s functions.php file or a site-specific plugin.


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

add_filter( 'pre_get_posts', 'exclude_category_home' );

Don’t forget to replace ID (-5) with your category ID. It will hide all blog posts from homepage belonging to the category that matches this ID.

Note: Make sure to add a minus (-) sign with the category ID.

Not sure how to find the category ID? See our guide on how to find category IDs in WordPress.

If you want to exclude multiple categories, then you can change the code like this:


function exclude_category_home( $query ) {
if ( $query->is_home ) {
$query->set( 'cat', '-5, -9, -23' );
}
return $query;
}

add_filter( 'pre_get_posts', 'exclude_category_home' );

Simply replace the IDs (-5, -9, -23) with your category IDs to exclude them from your WordPress homepage.

We hope this article helped you learn how to exclude a category from your WordPress homepage. You may also want to see these most wanted category hacks and plugins for WordPress that will help you use categories more efficiently.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit – a collection of WordPress related products and resources that every professional should have!

Reader Interactions

12 CommentsLeave a Reply

  1. i use a specific page to display recent posts. so i think for my case it should not be /code $query->is_home /code
    what should i put instead of “home”
    i want to hide specific category from “blog”

    • The code should work the same for your blog page if you set a page for your recent posts.

      Admin

  2. Hi,
    How to exclude whole category and custom from the search form or can I modified search form to just search by a specific taxonomy rest all are excluded from the search

  3. Thanks for the tip, I began using the plugin to exclude theme-specific content posts (testimonials, sliders) on my website!

  4. I followed the Method 2 instructions, but after the change the media library doesn’t work anymore!

    • The code should not affect your media library unless there is a larger error that is affecting your site. It would depend on the error message for the reason.

      Admin

  5. Thanks for this article.

    I want to ask if it’s also possible to exclude Google Adsense ads from some specific categories

Leave A Reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.