Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How To How to Exclude a Category From Your WordPress Homepage
#1
I think this is my first post here.. Lol..  Big Grin Big Grin
[Image: excludecategory-1-khodex.png]
This method requires you to add code to your WordPress files. If you haven’t done this before, then see our guide on how to copy and paste code snippets in WordPress.

You will need to add following code to your theme’s functions.php file or a site-specific plugin.

PHP Code:
function exclude_category_home$query ) {
if ( 
$query->is_home ) {
$query->set'cat''-5' );
}
return 
$query;
}
 
add_filter'pre_get_posts''exclude_category_home' ); 


Don’t forget to replace ID (-5) with your category ID. It will hide all blog posts from homepage belonging to the category that matches this ID.

Note: Make sure to add a minus (-) sign with the category ID.

Not sure how to find the category ID? See our guide on how to find category IDs in WordPress.

If you want to exclude multiple categories, then you can change the code like this:


PHP Code:
function exclude_category_home$query ) {
if ( 
$query->is_home ) {
$query->set'cat''-5, -9, -23' );
}
return 
$query;
}
 
add_filter'pre_get_posts''exclude_category_home' ); 


Simply replace the IDs (-5, -9, -23) with your category IDs to exclude them from your WordPress homepage. We hope this article helped you learn how to exclude a category from your WordPress homepage. You may also want to see these most wanted category hacks and plugins for WordPress that will help you use categories more efficiently. In Case Any Issues, Chat me on Messenger @DonKhodex
Creativity Speaks!!! , Chat Me on Messenger @DonKhodex // +2349099784140
#2
Welcome  Arrow
To Purchase Credit Click here , For how to make money on Sologet forum Click here 

HIRE ME FOR WEBSITE DESIGNING USE THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  HOW TO How To Convert A Wordpress Theme Into A Blogger Template lagosmp 2 633 08-20-2019, 01:39 PM
Last Post: Nupe360
  6 Easy Steps On How to Write a Blog About Home Improvement Kingsolomon 0 67 08-04-2019, 06:51 AM
Last Post: Kingsolomon
  How To Use Mp3 Tag Editor Script Free Download Emvidowealth 1 66 08-02-2019, 09:25 AM
Last Post: Kingsolomon
  WOW Get approved by Google Adsense in 3-5 days Opoopo 0 337 06-13-2019, 05:02 PM
Last Post: Opoopo
  TIPS How to add voice tag in a music using your Android phone Kingsolomon 0 494 06-01-2019, 12:38 PM
Last Post: Kingsolomon

Forum Jump:


Users browsing this thread:
1 Guest(s)

How to Exclude a Category From Your WordPress Homepage00