How to exclude / hide posts of a category (or multiple categories) from displaying in the blog homepage?


Suppose you have a blog on WordPress setup and customization, and you want to hide “Books Review” and “Hosting Review” from blog homepage(is_home). Because you want to place them in the navigation menu.

So here is an easy tutorial at your service.

  • You have to find the category id for each categories. You can find them from Dashboard > Posts > Categories, click on Edit and take a note of the number beside tag_ID=. Repeat the step if you want to exclude multiple categories.
  • Now open functions.php file from WordPress theme folder. If you are using our basic WordPress child theme, you may have to create a file called functions.php.
  • Paste the following code in the file.
1
2
3
4
5
6
function exclude_category( $query ) {
    if ( $query->is_home ) {
        $query->set( 'cat', '-15,-48' );
    }
}
add_action( 'pre_get_posts', 'exclude_category' );
  • Number represents the category id. Suppose your Book Review category id is 15 and Hosting Review category id is 48. If you have multiple category, add a minus (-) before your category id and add them with a comma (,) separators as we did.
  • Now save the file and upload to your theme folder.
  • Refresh your homepage. I believe you have successfully excluded all posts of a category (or multiple categories) from your homepage.

Request for this article came from one of our readers via Ask for Help section. If you want some help, why don’t you leave a comment or ask for professional WordPress help and our team will contact you shortly.

Regards,
Jinnat Ul Hasan

By | On Wednesday, August 24th, 2011 | Under How To's | No Comments ยป


DO YOU NEED OUR HELP?

Contact our experts, most of the time we assist our readers free of charge.

Those who found this page were searching for:

  • how to exclude a category from frontpage wordpress twentyeleven
  • wordpress exclude post with multiple categories
  • how to hide pposts from displaying in home page in wordpress
  • how to exclude posts category page
  • hide post category from blog
  • wordpress exclude multiple categories
  • WORDPRESS exclude tag_id search
  • multiple categories post homepage wordpress
  • remove category posts from homepage
  • how to exclude post from category in wordpress

Previous post:

Next post: