Last active
December 17, 2015 19:19
-
-
Save kachi/5659859 to your computer and use it in GitHub Desktop.
classを追加
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
<?php | |
add_filter ( 'wp_tag_cloud', 'tag_cloud_current_tag_highlight' ); | |
function tag_cloud_current_tag_highlight( $return ) { | |
$post_tags = array(); | |
if(is_single()) { | |
global $post; | |
$post_tags = get_the_terms($post->ID,'post_tag'); | |
} | |
if(is_tag()) { | |
$tags = explode( '+', get_query_var('tag') ); | |
foreach( $tags as $tag ) { $post_tags[] = get_term_by('slug',$tag,'post_tag'); } | |
} | |
if( $post_tags ) { | |
foreach ($post_tags as $pt) { | |
$tag = $pt->term_id; | |
if(preg_match("#-link-" . $tag . "' #", $return)) { | |
$return = str_replace("link-" . $tag . "' ", "link-" . $tag . " current-tag' ", $return); | |
} | |
} | |
} | |
return $return; | |
} | |
//current-tagというclassが追加される | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment