Display selected category on post page

I personally like to take all the categories a post is attached to and slap an active class onto them. Here’s the code I found and currently use.

/** Active Category **/
// Single Posts only
function singlePostActiveCat ($CatText) {
 global $post;
 if (is_singular()) {
   $categories = wp_get_post_categories($post->ID);
   foreach ($categories as $category_id) {
    $category = get_category($category_id);
    $CatText = preg_replace(
       "/class=\"(.*)\"><a ([^<>]*)>$category->name<\/a>/",
       ' class="$1 current-cat"><a $2>' . $category->name . '</a>',
    $CatText);
    }
 }
return $CatText;
}
add_filter('wp_list_categories', 'singlePostActiveCat');