Skip to content

Instantly share code, notes, and snippets.

@DaDlugosch
Forked from dylanjameswagner/tag-cloud.php
Created March 2, 2021 13:24
Show Gist options
  • Select an option

  • Save DaDlugosch/6b962d2b366149a6818300572f692d68 to your computer and use it in GitHub Desktop.

Select an option

Save DaDlugosch/6b962d2b366149a6818300572f692d68 to your computer and use it in GitHub Desktop.
Add an active class to the current tag in a tag cloud widget.
function carbon_tag_cloud_class_active($tags_data) {
$body_class = get_body_class();
foreach ($tags_data as $key => $tag) {
if(in_array('tag-'.$tag['id'], $body_class)) {
$tags_data[$key]['class'] = $tags_data[$key]['class'] ." active-tag";
}
}
return $tags_data;
}
add_filter('wp_generate_tag_cloud_data', 'carbon_tag_cloud_class_active');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment