Exclude a category from the filed under list

I have a site where I have a category that I'm using for some backend functionality. However, when I'm viewing a post that is in that category and other categories, I don't want to see that category in the list of categories that the post is "filed under" or "posted in" or whatever it's called.

To make it clearer - I have a category X that I'm using to do stuff for the theme. The post is categorized in A, B and X. On the post page, it says "Filed Under: A, B, X". I would like it to say "Filed Under: A, B"

I was looking for a way to exclude that category id from the get_terms call, but I'm not sure how to go about it. Is that even the right way? I originally thought this was a post_meta issue, but it seems it's get_terms related. Can I add a filter on get_terms to always exclude a category?

If it matters, I'm using the genesis framework, and this call happens in the do_action('genesis_after_post_content') call. But again, if I can add this as a global filter in my functions.php that'd be the best solution.

I have tried the method mentioned in this post, but it did not work.

Topic terms post-meta genesis-theme-framework Wordpress

Category Web


I have found an answer at this article entitled "Excluding Categories from the_category();":

function the_category_filter($thelist,$separator=' ') {
     // list the IDs of the categories to exclude
     $exclude = array(4,5);
     // 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', 10, 2);

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.