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:
- Install a plugin
- 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.
This no longer works with the most recent Genesis updates.
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.
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.
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?
Hmmm. Maybe this would do it?
Forgive the messy code layout.
YEP! It works.
If you want to include more use this syntax
I grabbed this info from https://premium.wpmudev.org/blog/one-category-wordpress-homepage/
Thanks for sharing.
Yes, you simply remove the minus sign before each category I.D
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
No worries Chris.
Thanks for the positive feedback.
Merry Xmas!!
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
Have you asked this question on the StudioPres forums?