Exclude a Category Posts from the Home Page in WordPress

Exclude a Category Posts from the Home Page in WordPress

Today i will tell you how to hide a specific category all post from the blog home page. If you want tot hide a specific category all Post or More tah one category then create a function and this function in your theme function file.

How to Find the Post category Id

To find a category id we can edit any post from this category.If we have create a New category first create a new post under this category after tahn edit this post and get the category id.

1

2

3

4

5

6

7

8

9

10

//To hide a single category where category id 16

/** Exclude certain category from posts */

add_action('pre_get_posts','be_exclude_category_from_blog');

functionbe_exclude_category_from_blog($query){

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

$query->set('cat','-16');

}

}

Note : include the negative symbol before your category is Prevents to display specified categories posts. We can Prevents to display more than one category post using this method. To adding another categories.