Divi WordPress Theme
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

WordPress fix Excluding category form home page code not working?

Discussion in 'Misc WordPress Requests' started by scm22ri, Jan 5, 2018.

  1. scm22ri

    Guest

    Excluding category form home page code not working?, by scm22ri

    Hi Everyone,

    I’m trying to exclude a certain category form my WP homepage. I found the below code on the internet but unfortunately it’s not working. I’m adding the syntax to the functions.php page in my theme but it’s not working. Can anyone help me with this? Thanks

    // How to hide certain categories from your homepage
    // https://wpmayor.com/how-to-hide-or-remove-categories-from-a-wordpress-homepage/
    function exclude_category_home( $query ) {
    if ( $query->is_home ) {
    $query->set( 'cat', '-8' );
    }
    return $query;
    }

    add_filter( 'pre_get_posts', 'exclude_category_home' );

    Excluding category form home page code not working?
     
    #1

Share This Page

Monarch Social Sharing Plugin