• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

WP SITES

2784

Original Genesis Tutorials & 6000+ Guaranteed Code

Snippets

  • Consultation
  • Full Access
  • Log in

How To Exclude Posts In Specific Categories From Displaying

There’s different ways you can exclude all posts in one or more categories from displaying on your home and/or blog pages.

We’ll be using pre_get_posts

pre_get_posts should be used in custom functions. (child themes)

You can:

  1. Install a plugin
  2. Add a custom function to your child themes functions.php file

Demo Video #

Shows all posts in category 9 which is the lifestyle category, removed from the front page loop.

Add Code To Themes Template Files

You could also add the above code to any theme which uses an index file like one of the default WordPress themes. Preferably not in the parent theme.

Another option would be to add this code into your home.php file within the loop.

pre_get_posts & Category_Parameters Function

Use this code in your child themes functions.php file.

This is the best method in my opinion.

You can change the category parameters and conditional tag to suit your needs.

Or this method :

This code works with Genesis theme framework and excludes posts from category 27 and 30 from displaying on the home page.

It wouldn’t be difficult to change the is_home conditional tag and replace with your own category i.d’s.

Related Tips

  • 3 Ways To Remove or Exclude Posts From Your Home Page Loop

Reader Interactions

Comments

  1. Kevin Eberle says

    June 25, 2019 at 1:26 pm

    This no longer works with the most recent Genesis updates.

    Log in to Reply
    • Brad Dalton says

      June 25, 2019 at 8:42 pm

      On which page? For your front page? Are you using a front-page.php template? Or have you changed the Reading settings for the front page displays? The genesis blog page template has been removed.

      Log in to Reply
    • Brad Dalton says

      June 27, 2019 at 12:04 am

      What you can do is create a page named blog and set that as your posts page in your Reading settings. Then you can use a front-page.php file for your front page.

      Log in to Reply
  2. bluefox42 says

    May 19, 2016 at 8:36 am

    Brad,

    Thanks for this. I have 30 categories. I’m wondering, is there a way to only show just one category instead of excluding many?

    Log in to Reply
    • bluefox42 says

      May 19, 2016 at 8:45 am

      Hmmm. Maybe this would do it?

      function my_home_category( $query ) { if ( $query->is_home() && $query->is_main_query() ) { $query->set( 'cat', '11'); } } add_action( 'pre_get_posts', 'my_home_category' );

      Forgive the messy code layout.

      YEP! It works.

      If you want to include more use this syntax

      $query->set( 'cat', 11, 14 );

      I grabbed this info from https://premium.wpmudev.org/blog/one-category-wordpress-homepage/

      Log in to Reply
      • Brad Dalton says

        May 19, 2016 at 9:20 am

        Thanks for sharing.

        Yes, you simply remove the minus sign before each category I.D

        $query->set( 'cat', '27,30' );
        Log in to Reply
  3. Chris Praetorius says

    December 15, 2014 at 3:27 pm

    Hello Brad,

    I thank you so much for this usefull code, it took me hours of successless try’n’rollback, before I found your snippet. I’m really glad about your help, one big point on my todo-list is now marked as “cleared”.

    Thank you!

    Regards
    Christian

    Log in to Reply
    • Brad Dalton says

      December 15, 2014 at 3:29 pm

      No worries Chris.

      Thanks for the positive feedback.

      Merry Xmas!!

      Log in to Reply
  4. Tarun says

    October 14, 2013 at 7:58 am

    Hello,

    Can you please let me know that how can we display the “Author box” and the social media sharing button in the first post when we go to category and tags with full post.

    Currently the full text is coming but Author box and social media sharing buttons are not coming. i am using Genesis theme. Please let me know how can we do that. It is urgent.

    Thanks

    Log in to Reply
    • Brad Dalton says

      October 14, 2013 at 8:03 am

      Have you asked this question on the StudioPres forums?

      Log in to Reply

Leave a Reply Cancel reply

You must be logged in to post a comment.

Primary Sidebar

Code written by Brad Dalton specialist for Genesis, WooCommerce & WordPress theme customization. Read More…

Advertise · WPEngine · Genesis · Log in

  • Access Problems
  • Account Details
  • Consulting
  • Tags