Site logo

Archived topic

Exclude categories from blog page only

3 replies · Started by Incal on July 4, 2022

Viewing posts 1–4 of 4

Hi Kevin,

The code should exclude the category from the blog page loop, it won't affect the other archive page's loop.

But GB loop uses the blog loop by default if there is no other parameter set.

You can try modify the PHP code to this:

add_filter('pre_get_posts', 'excludeCat');
function excludeCat($query) {
      if ( $query->is_home && is_home()) {
            $query->set('cat', '-3,-5,-23');
      }
      return $query;
}

Hi Ying,

That's exactly what I was looking for!

Thank you once again for your help.

Kevin

You are welcome Kevin :)

This archived topic is closed to new replies.