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 US THE PM BUTTON TO SEND ME MESSAGE

There is love in sharing
  


Possibly Related Threads...
Thread Author Replies Views Last Post
  HOT bet entertainment that accept guest post Beecoded 0 32 05-04-2019, 05:01 PM
Last Post: Beecoded
  HOW TO How To Convert A Wordpress Theme Into A Blogger Template lagosmp 1 343 02-06-2019, 08:20 PM
Last Post: Kingsolomon
  WOW How to Change WordPress Theme via phpMyAdmin khodex 2 316 01-18-2019, 07:36 AM
Last Post: olades
  TIPS How To Allow Automatic Database Repair In Wordpress khodex 2 332 01-16-2019, 07:42 PM
Last Post: pola
  HOW TO How to Fix Too Many Redirects Errors After Moving to SSL / HTTPS khodex 1 248 01-09-2019, 07:56 AM
Last Post: Kingsolomon

Forum Jump:


Users browsing this thread:
1 Guest(s)

How to Exclude a Category From Your WordPress Homepage00