• Resolved Janek Krause

    (@janekkrause)


    Hi there,

    Just wondering if theres a way to exclude a post category from the News Section on the homepage. I’ve got some posts appearing on the front page I’d like to remove.

    Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hello @janekkrause

    Copy the below code and paste it in functions.php file, right before the ?> (at the bottom of the file).

    function exclude_category($query) {
    if ( $query->is_home() ) {
    $query->set('cat', '-6');
    }
    return $query;
    }
    add_filter('pre_get_posts', 'exclude_category');

    Set your category eg: If your category id is 6 then write it like

    If you want to exclude more than one category then set it like:
    $query->set('cat', '-3,-5,-23');

    Regards

    Thanks @wbcomdesigns

    Thread Starter Janek Krause

    (@janekkrause)

    Thanks! Works like a charm. ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Exclude post category from homepage News Section’ is closed to new replies.