How to Exclude a Category from Your WordPress Homepage

How to Exclude a Category from Your WordPress Homepage

For one reason or another, you may not want posts from one or more categories appearing in the stream of posts that show up on your homepage. This little bit of code will let you remove whichever categories you like from that stream.

Place the following into your functions file. (Appearance > Editor > Theme Functions – functions.php)

In this example, the numbers 3, 5, and 23 are the category IDs (don’t forget the minus signs in front of them). Choose your own categories to be excluded by finding the category ID. If you aren’t sure how to do that, see this post.
{code type=php}
function excludeCat($query) {
if ( $query->is_home ) {
$query->set(‘cat’, ‘-3,-5,-23’);
return $query;
add_filter(‘pre_get_posts’, ‘excludeCat’);

Thanks to wp-snippets for this very handy little piece of code.

Photo credit: Willi Heidelbach

Free Video Why 100 is NOT a Perfect Google PageSpeed Score (*5 Min Watch) Learn how to use Google PageSpeed Insights to set realistic goals, improve site speed, and why aiming for a perfect 100 is the WRONG goal.