Exclude Posts From a Specific Category on Wordpress Homepage

January 22, 2010

If you don’t want posts from a specific category to appear on homepage, then you can easily do that by editing the wordpress loop.

Open the theme editor in wordpress dashboard (Appearence > Editor) and open home.php file. If you don’t see home.php file then click on index.php file. Then look for the start of the wordpress loop,

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

Now, just below this, add the line,

if (is_home()) if (in_category('7')) continue;

That’s it. Now the posts from category id 7 will not appear on homepage.

Note 1 - If you don’t know how to find the id of a category, then check this post.

Note 2 - If you are using a magazine theme or a theme that uses many loops on homepage, then make sure that you are editing the correct loop or you may break the whole site. If you are not sure about what you are doing, then let handyman do that dirty work.