So you are probably here because you want to know how to exclude a single category, or multiple categories from the homepage of your wordpress blog/website. If you don’t want to use a plugin, here is a very simple code that have to be included in the funcions.php file, located in your theme folder.


function thegure_exclude_cat( $query ) {

if ( $query->is_home() && $query->is_main_query() )

$query->set( 'cat', '-1,-2,-3' );

return $query; }

add_filter( 'pre_get_posts', 'thegure_exclude_cat' ); ?>

In the above code you will have to replace the numbers: -1,-2,-3 with the category IDs you want to exclude. Now probably you ask yourself, how do I know that number? Well, it is simple, I will explain.

After you create your categories, go and edit the category you want to exclude. Find the “tag_ID=” in the URL and the number that follows this tag will be the category ID. Just like in the image bellow:

find category id wordpress

This article has 1 comment

Leave a Comment

Your email address will not be published. Required fields are marked *