• Is there any way to hide a category totally from the front page? I want to use posts for other sections, that I don’t really want to show on the front page as “news” posts.

    Thanks

Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi neiljordan. You can use the WP pre_get_posts() function in a child theme functions.php file. If you don’t currently have a child theme you can install one using the instructions here:
    http://docs.presscustomizr.com/article/239-using-a-child-theme-with-hueman

    Add this to your child theme; change the ‘-1’ category parameter to the category ID of your “news” category:

    // exclude "news" category from home page 
    function nj_exclude_category( $query ) {
        if ( $query->is_home() && $query->is_main_query() ) {
            $query->set( 'cat', '-1,');
        }
    }
    add_action( 'pre_get_posts', 'nj_exclude_category' );
    • This reply was modified 9 years, 7 months ago by bdbrown.
    Thread Starter NeilJordan

    (@neiljordan)

    Thanks for the information.

    Ideally I want to “exclude” some sections from the front rather than have to have a specific category to include if that is possible? The items on the front page will come from a number of categories that will be expanding over time, so I would rather not have to list them explicitly, just exclude posts from a small number of categories that will be relatively fixed.

    Thread Starter NeilJordan

    (@neiljordan)

    Ah – sorry, I didn’t understand the relevance of the minus in the category number to exclude that particular one.

Viewing 3 replies - 1 through 3 (of 3 total)

The topic ‘Hide Category from Front Page’ is closed to new replies.