Created
November 27, 2014 07:44
-
-
Save pigmentGit/bf474737810ad3e228bf to your computer and use it in GitHub Desktop.
Lägg till class på aktiv kategori i kategorilista
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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