Skip to content

Instantly share code, notes, and snippets.

@kachi
Last active December 17, 2015 19:19
Show Gist options
  • Save kachi/5659859 to your computer and use it in GitHub Desktop.
Save kachi/5659859 to your computer and use it in GitHub Desktop.
classを追加
<?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