How to add a class to Tag Cloud items – WordPress

If you want to extend the WordPress Tag Cloud Widget with your own custom CSS class, you can easily use the wp_generate_tag_cloud_data filter like so:

function extend_tag_cloud($tag_data) {
  return array_map (
      function ( $item )
          $item['class'] .= ' your-custom-class';
          return $item;
      (array) $tag_data
add_filter( 'wp_generate_tag_cloud_data', 'extend_tag_cloud');Code language: PHP (php)


Leave a Reply

Your email address will not be published. Required fields are marked *