• Skip to main content

Eric L. Ingram

WordPress Consultant

  • HOME
  • ABOUT
  • WORK

Tutorial

Exclude category from recent posts

November 19, 2011 By Eric Ingram

If you are looking for a way to exclude category from recent post (post that show up on your homepage).  Here is a quick and simple way to do it.  First find the category id by editing the category you want to exclude.  From your dashboard click Categories and edit the category you want to exclude. .  Once you select edit, in the URL you’ll see the category ID.  Make a note of this number.

I use frameworks (genesis), so I would open my child theme functions.php file. And add the following code:

//Exclude category from recent posts
add_filter(‘pre_get_posts’, ‘exclude_category_from_home’);
function exclude_category_from_home($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-id‘);
}
return $query;
}

Now just replace the “id” with your category number save the file and there you have it.

Copyright © 2021 ·Genesis Framework · Site by Eric Ingram