Site logo

[Support request] How to not show a specific Category in the Blog Layout on the Home page?

Home Forums Support [Support request] How to not show a specific Category in the Blog Layout on the Home page?

Home Forums Support How to not show a specific Category in the Blog Layout on the Home page?

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2492715
    Raj

    I want to hide a specific category from the front page (home page) blog section. Please help me. I read other similar threats but they were of no use to me, as I don’t have much coding knowledge. Can some one please help me with a step by step guide?

    #2493090
    David
    Staff
    Customer Support

    Hi there,

    this is the PHP Snippet you require:

    
    function exclude_posts_from_home_page( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $term_id = get_cat_ID( 'term-slug' );
            $query->set( 'category__not_in', array( $term_id ) );
        }
    }
    add_action( 'pre_get_posts', 'exclude_posts_from_home_page' );

    In the code you will see: $term_id = get_cat_ID( 'term-slug' ); change the term-slug to match your term.

    Question – are you using a Child Theme?
    If Yes, then add the code to your Child Themes functions.php

    If NO, then install the Code Snippets plugin, Add New Snippet and add the code there.

Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.