Exclude posts from WordPress home page based on their category

There may be situations where we want to exclude posts from the WordPress home page based on their category.

To get this done, first we want to find template file for home page. Very often, it will be index.php in our theme folder. Then find the below line of code on it.

<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

Just replace this line with below code.

<?php query_posts('cat=-4'); ?>
<?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>

This will exclude posts in category number four from being displayed on the home page.

Need Help?

Do you need any help on WordPress? I'm happy to help you.

Contact Me

Recent Posts

  1. Update query order - WordPress
  2. Display featured products - WooCommerce
  3. Remove "Category:", "Tag:", "Author:" from the_archive_title - WordPress
  4. The essential & basic WP-CLI commands for a WordPress developer
  5. Install theme unit test data using WP-CLI - WordPress


Questions / Comments

If you found this article interesting, found errors, or just want to discuss about them, please get in touch.