On a recent WordPress website project I was working on, I needed to remove specific categories from the list of categories that the “get_category()” function returns. Carl Bliss discovered the solution on the Technokinetics blog.

First, add the following to functions.php:

cat_name != 'CATEGORY TO EXCLUDE' && $category->cat_name != 'ANOTHER CATEGORY TO EXCLUDE') {
	  if ($first_time == 1) {
		echo 'name ) . '" ' . '>'  . $category->name.'';
		$first_time = 0;
	  } else {
		echo $separator . 'name ) . '" ' . '>' . $category->name.'';
	  }
	}
  }
}
?>

Make sure to replace the “CATEGORY TO EXCLUDE” text with your category’s nicename.

Then add the following to your theme:


That’s it!

1 Comment

  1. jogol on June 5, 2011 at 6:26 pm

    //exclude categories with id 1 and 3
    $args = array(‘exclude’ => array(1,3));
    $categories = get_categories( $args );