I always assumed there was a way to exclude certain categories from being output in the loop using get_the_category, the_category, or one of the term related functions. After looking around it seems like the only way is to grab the array and just remove them by ID or name.

For instance this is what I am using:

<?php // exclude category ID 12 as an example.

      foreach((get_the_category()) as $cat) {
        if (!($cat->cat_ID =='12'))
         echo '<a href="' . get_bloginfo('url') . '/category/' 
         . $cat->category_nicename . '/">'. ' | ' . $cat->cat_name . '</a>';

This looks kinda messy due to having a somewhat "hard-coded url" using /category/ ( I know I can also change this but it still seems counter intuitive).
Is there no better way to exclude categories?

  • You can run a filter on list_terms_exclusions to exclude terms site wide, or simply one side or the other(admin or front)...
    – t31os
    Jul 26, 2011 at 11:20
  • Ok I tried this but could not get it to work, here are some examples I tried, pastebin.com/j4KKPFKY, any insight?
    – Wyck
    Jul 26, 2011 at 17:10

1 Answer 1


If the URL being "hard-coded" is the problem you can use get_category_link

foreach((get_the_category()) as $cat) {
    if ($cat->cat_ID !='12')
        echo '<a href="'.get_category_link($cat->cat_ID).'"> | ' . $cat->cat_name . '</a>';
  • Thanks Bainternet, this does work but after thinking about it I want to remove it from all side wide output (front-end) instead of changing all the templates, I have updated my question.
    – Wyck
    Jul 26, 2011 at 17:24

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