Exclude Certain Categories from the Homepage on WordPress Blogs

wordpress blue and white and grey logo

If you are using WordPress for your blog then you will probably be using your latest posts to make up your home page.

By default, all categories of posts are included in your home page, but what if you want to exclude a category or multiple categories of posts from displaying on your home page?

Well, it is pretty simple…

First you need to edit your themes functions.php file. To do this, login to your WordPress Dashboard and click Appearance > Editor:

Then on the right hand side are the files you can edit. You should click on “Theme Functions (functions.php)“:

You should then add this code:

function excludeCat($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-6,-9,-17’);
return $query;
add_filter(‘pre_get_posts’, ‘excludeCat’);

Here you will see -6,-9,-17, these are the important numbers that you need to amend. These are actually the category ID’s of the categories that you want to exclude from showing on your home page.

So how do you find your category ID so that you can amend them in the above code?

All you have to do is click on Posts > Categories:

Once in the category section you will see all your categories listed on the right hand side:

If you right click on the category you want to exclude and open in a new tab, you should now see in the address bar of your browser tag&categoryID=:

Next to this will be a number – this is the number of this category. In our example, the number is 9.

So, you would then enter the code with a -9 to exclude that category. So as per our example, the code would then be:

function excludeCat($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-9’);
return $query;
add_filter(‘pre_get_posts’, ‘excludeCat’);

One you are happy that you have the correct code in place you can go ahead and save the functions.php file in your theme.

Now, when you load your home page, the category you added to the functions.php file will now not show on your home page.


This is a theme edit so any updates will over write it. So, you either will need to re-add it after any updates or what you really should do is your a child theme so you only have to carry this out once without fear of a theme update wiping out all your hard work!


If you have any questions or feedback on this guide, please feel free to leave us a message below and we will try and reply as soon as we can.

Free Subscription!Subscribe to our site to receive updates via email!

Enter your email address below and click the Subscribe button to receive email notifications about new and exciting downloads available through our website at https://www.techygeekshome.com

You will also receive notifications about new technical guides, latest news and MSI installer downloads that are available through our blog here at https://blog.techygeekshome.info 

We will not spam you and we will not pass on any of your details to anyone else. We tend to post new content once or twice a week.

Join 236 other subscribers

You can unsubscribe any time you like.

About A.J. Armstrong

Founder of TechyGeeksHome and Head Editor for over eight years! IT expert in multiple areas for over 20 years. Sharing experience and knowledge whenever possible! Making IT Happen.

View all posts by A.J. Armstrong