Support » Theme: ColorMag » Excluding ports from Homepage

  • Resolved shulini

    (@shulini)



    Is it possible to not display post from a specific category in the homepage?
    I did create a new category that I will be using for a special page, but I do not want those posts to show in the homepage.
    Thanks!

    • This topic was modified 2 years, 1 month ago by  shulini.
Viewing 3 replies - 1 through 3 (of 3 total)
  • In your theme‚Äôs functions.php file, you can add the following code, replacing in the third line the category IDs you want to exclude. In this example, I exclude the categories with ID numbers 2 and 3.

    
    function exclude_category_home( $query ) {
    if ( $query->is_home ) {
    $query->set( 'cat', '-2, -3' );
    }
    return $query;
    }
    
    add_filter( 'pre_get_posts', 'exclude_category_home' );
    

    If you don’t want to edit your theme’s functions.php file, you can create your own plugin, or if you have already created, simply throw in the code shown.

    Another solution, maybe this plugin solves your need Ultimate category excluder.

    Regards

    • This reply was modified 2 years, 1 month ago by  Gabri Gonzalez. Reason: Add a related plugin

    Thank you so much!
    The code didn’t work, but the plugin works perfectly.

    I tried the code in my local installation before posting here and runs ok.

    Be sure to write your ID values separated by commas, and all of them within single quotes.

    $query->set( 'cat', '-ID1, -ID2, -ID3' );

    or

    $query->set( 'cat', '-ID4' );

    Please, mark as resolved the thread if it is.

    Regards.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Excluding ports from Homepage’ is closed to new replies.