WordPress: exclude categories from being displayed on home page.

PHP code to put in the file function.php of your child theme:
// Used to limit the categories displayed on the home page.
function exclude_category($query) {
if ( $query->is_home ) {
$query->set('cat', '-11,-12,-13');
return $query;
add_filter('pre_get_posts', 'exclude_category');

Note: replace -11, -12, -13 with the ID# of your categories.


Read more here:


Simple Exclude Plugin: http://www.codehooligans.com/2008/04/27/simply-exclude-plugin/


Question: How to find WordPress category ID?

Answer: Go to Manage Categories in Dashboard, simply put your mouse cursor on the “Edit” link related to the category you want to know the ID and look on your browser’s status bar, you’ll see the ID#.



  1. Pictrix
    Posted June 3, 2010 at 9:56 pm | Permalink

    I followed your instructions for setting a certain category in its own page. Now I am looking to exclude categories from being displayed in the “Posts Page” (blog) since I have set a Static Page for the Front Page.

    I tried using

    if ( $query->is_feed ) {

    in your code above, but all I get is a parsing error. Do you have any suggestions? They’ll be greatly appreciated.

  2. Fanatic
    Posted December 18, 2011 at 12:58 pm | Permalink

    The reason why you’re getting a parse error is due to this line:
    $query->set(‘cat’, ‘-11, -12, -13′);
    After the -13, this character “‘” is pasted wrong, just make sure it is the ‘ and nothing else and the error code will go away.

    Tested this code and works like a charm, categopry posting excluded from the main blog paage but it shows up under a seperate page I created.

    Thank you for the code.

%d bloggers like this: