Skip to content

Instantly share code, notes, and snippets.

@pigmentGit
Created November 27, 2014 07:44
Show Gist options
  • Save pigmentGit/bf474737810ad3e228bf to your computer and use it in GitHub Desktop.
Save pigmentGit/bf474737810ad3e228bf to your computer and use it in GitHub Desktop.
Lägg till class på aktiv kategori i kategorilista
// add class to active cat
function tax_cat_active( $output, $args ) {
if(is_single()){
global $post;
$terms = get_the_terms( $post->ID, $args['taxonomy'] );
foreach( $terms as $term )
if ( preg_match( '#cat-item-' . $term ->term_id . '#', $output ) )
$output = str_replace('cat-item-'.$term ->term_id, 'cat-item-'.$term ->term_id . ' current-cat', $output);
}
return $output;
}
add_filter( 'wp_list_categories', 'tax_cat_active' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment