ControlledChaos
5/7/2015 - 9:43 AM

Add .current-cat Class To Categories List In Single Post

Add .current-cat Class To Categories List In Single Post

<?php

function ccd_style_current_cat_single_post( $output ) {
    if( is_single() ) :
        global $post;
        foreach ( get_the_category( $post->ID ) as $cat ) {
            $cats[] = $cat->term_id;
        }
        foreach( $cats as $value ) {
            if( preg_match( '#item-' . $value . '">#', $output ) ) {
            $output = str_replace( 'item-' . $value . '">', 'item-' . $value . ' current-cat">', $output );
            }
        } endif;
    return $output;
}
add_filter( 'wp_list_categories','ccd_style_current_cat_single_post' );

?>

Add .current-cat Class To Categories List In Single Post

WordPress Snippet