Question

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?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with wordpress.stackexchange
scroll top