Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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(!in_array($catname,$exclude2))

      // 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

1 Answer 1

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

 
discard

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.