In WordPress, we assign different category to set of posts for better overall organization. This helps in better management and easier content discovery. Sometimes we need to exclude the display of specific posts on the blog homepage but show all other posts. This can be easily achieved by assigning same category to all those posts and use following code in functions.php file.

[cc lang=”php”]
//Exclude one category on homepage
add_filter(‘pre_get_posts’, ‘exclude_category_from_home’);
function exclude_category_from_home($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-15’);
return $query;

Above 15 is the ID of the category whose posts wont be displayed on the homepage. You can replace it with any required category ID as on your blog.

To find ID of specific category, open category page from left sidebar in WordPress dashboard. Then mouse over the specific category to view full url at the bottom showing ID at the end.

Davinder Singh Kainth

A digital creator with 15+ years of experience in Website Design, Development, SEO, and Content Creation to Podcasting at with the motto of "Be Smart, Keep Creating". A coach, consultant, and your dear geek friend ❖

Leave a Comment