This question already has an answer here:

I use the built-in tag cloud widget and it's outputting the terms with a title attribute on hover that says "x Topics". How can I remove this title attribute, or better yet, change it to something more meaningful for the current terms.

I have already tried this code, but it does not appear to be working:

// remove the title attribute from tag cloud widget
add_filter('wp_widget_tag_cloud', 'remove_tag_title_attributes');
function remove_tag_title_attributes($output) {
    $output = preg_replace('title="(.+)"', '', $output);
    return $output;

marked as duplicate by fuxia Jul 20 '13 at 14:06

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

  • 1
    Maybe this plugin is what you're looking for? wordpress.org/plugins/ultimate-tag-cloud-widget/other_notes Looks like you can edit the title and then some. – mtuttle Jul 20 '13 at 12:15
  • @mtuttle I've seen that plugin before but didn't want all the functionality. However, since there appeared to not be a native hook for changing the title, I've just used it for now. Thanks. – Hassan Jul 20 '13 at 21:10

Why did you think that code would work? There is no hook named wp_widget_tag_cloud that I can find, and there is no hook specifically meant for altering that attribute. But you can pass a topic_count_text_callback to wp_tag_cloud, which is what generates the tag cloud for the widget, and there is a hook that allows you to alter the widget's tag cloud arguments.

function tag_count_cb($count) {
  return 'test';

function remove_tag_title_attributes($args) {
  $args['topic_count_text_callback'] = 'tag_count_cb';
  return $args;
add_filter('widget_tag_cloud_args', 'remove_tag_title_attributes');

But you don't have much to work with-- just the tag count. To get more to work with you will need to do something more like what you trying but with a different regex and a different hook.

function tag_cloud_attribute_rebuild($match) {
  $a = "<a href='%s' class='%s' title='%s' style='%s'>%s</a>";
  return sprintf(

function remove_tag_title_attributes($output) {
  $pattern = "|<a href='([^']*?)' class='([^']*?)' title='([^']*?)' style='([^']*?)'>([^<]*)</a>|";
  $output = preg_replace_callback($pattern,'tag_cloud_attribute_rebuild',$output);
  return $output;
add_filter('wp_tag_cloud', 'remove_tag_title_attributes');

The title is $match[3]. The other information is to give you some information to work with. Alter $match[3] before the sprintf. If that isn't enough information you will have to extract the ID from $match[2] or use the tag name in $match[5] and run a query, but that will be very labor intensive for the server.

That is how you would do it with the Core widget. Another option would be to rebuild the widget under a different name-- that is, make your own widget using the Core widget as a model--and include altered versions of whatever functions you need.

  • Thanks for a comprehensive answer. I also checked the answer that @toscho linked to and this simple thing doesn't seem to be that simple. I'll just use a plugin until there is a native hook for altering the title attribute. – Hassan Jul 20 '13 at 21:07

Try this out:

function wp_tag_cloud_remove_title_attributes($return) {
        // This function uses single quotes
        $return = preg_replace("` title='(.+)'`", "", $return);
    return $return;
add_filter('wp_tag_cloud', 'wp_tag_cloud_remove_title_attributes');
  • This does remove the title, but for some reason it breaks the smaller/bigger terms output. Thanks anyway, I went with a plugin eventually. – Hassan Jul 20 '13 at 20:58

Not the answer you're looking for? Browse other questions tagged or ask your own question.