WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

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

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.