WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm using the following code, placed in the functions.php of my theme, to hide certain categories used to organise posts and populate sliders from the posts themselves and their category listings:

function the_category_filter($thelist,$separator=' ') {
 // list the IDs of the categories to exclude
 $exclude = array(1,32,42,4);
 // create an empty array
 $exclude2 = array();

 // loop through the excluded IDs and get their actual names
 foreach($exclude as $c) {
      // store the names in the second array
      $exclude2[] = get_cat_name($c);

 // get the list of categories for the current post     
 $cats = explode($separator,$thelist);
 // create another empty array      
 $newlist = array();

 foreach($cats as $cat) {
      // remove the tags from each category
      $catname = trim(strip_tags($cat));

      // check against the excluded categories

      // if not in that list, add to the new array
      $newlist[] = $cat;
 // return the new, shortened list
 return implode($separator,$newlist);

// add the filter to 'the_category' tag
add_filter('the_category','the_category_filter', 1, 32, 42, 4);

This works well, but it also hides the categories in the post edit backend. I can see the tick box, but the name of the category is hidden.

Can someone suggest a tweak to the above code that preserves its function of hiding categories on the frontend, but keeps categories visible in the post edit window / the WP backend?

share|improve this question

Just don't apply the filter if is_admin().

Unrelated- you should also take a look at add_filter, your arguments are not correct.

share|improve this answer
I'm really a beginner. I don't know how to add correctly 'is_admin()' – Ian Douglas Nov 23 '13 at 0:02
If anyone needs a solution, someone on Stackexchange helped resolve it: stackoverflow.com/questions/20180573/… – Ian Douglas Nov 24 '13 at 23:09

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.