Exclude WordPress Category from get_the_category_list

I have some code that lists the category of the post you are currently on like so…

<?php $categories_list = get_the_category_list( __( ', ', 'sitename' ) );
if ( $categories_list && sitename_categorized_blog() ) :?>
<span class="cat-links">
<?php printf( __( 'ALL NEWS FOR %1$s', 'sitename' ), $categories_list ); ?>
</span>
<?php endif; // End if categories ?>

This works great, but I just added a new ctegory called ‘featured-posts’. How do I exclude this featured-posts category (either by name or ID), from appearing in the menu generated by above code?

Read More

So instead of the result…

ALL NEWS FOR: CATEGORY NAME, FEATURED POST

I just get…

ALL NEWS FOR: CATEGORY NAME

Related posts

Leave a Reply

3 comments

  1. Explanation

    Hi, use wp_list_categories function instead and use ‘exclude’ argument.
    Refer to this codex page for further explanations.

    Example

    One place where you can put this code is inside your theme’s functions.php file. Following you have an example:

    function list_categories_without_this_cat() {
      $categories_stripped_of_one = wp_list_categories( array(
        'exclude' => array( 8 )
      ) );
      return $categories_stripped_of_one;
    }
    
  2. The problem with using list_categories is that it lists them in a list and not as it does with get_the_category_list using commas to separate.