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 want to include something like the the_category function in a WordPress post, which by default echoes a list of links to all categories the post is attached separated by comma, but I want to exclude some categories from listing in certain views. In some cases I have to exclude all children ones from appearing, in others a top category or random specific categories.

share|improve this question
add comment

1 Answer 1

Not sure but i think you can try this

function my_category_filter($cats){
   //exclude these from displaying
   $exclude = array("Large Announcement", "Announcement", "News");
   $Catds = array();
   foreach ($cats as$cat){
      if (!in_array($cat,$exclude)){$Catsa[] = $cat;}
   }
   return $Catsa;
}

add_filter('the_category','my_category_filter');
share|improve this answer
add comment

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.