Customizing WordPress Tag Tooltip Counter

WordPress wp_tag_cloud function will returns selected tag, category or custom taxonomy terms with cloud style if we use the smallest and the largest parameter. We will get the output in the same size if we set the same size to the parameters. And of course, with the tag tooltip.

By default, the function will return tooltip ‘%s topic’ for single and ‘%s topics’ for plural. We can modify the tag tooltip by using the topic_count_text_callback parameter with callback function or single_text and multiple_text parameter.

1 Using single and multiple text parameter

Simple method and clean. If you are using this method, please make sure you don’t use the topic_count_text_callback parameter. Open your template file such as single.php for single post view and paste the code below.

wp_tag_cloud( array( 
    'single_text' => 'Topic: %s',
    'multiple_text' => 'Topics: %s'

The function above echoes “Topic: 1” for single and “Topics: 5” for plural. Modify the text and the position of %s to your need.

2 Using callback function

This method uses additional callback function. Open your theme function.php and paste the code below.

function my_topic_count_text( $count ) {
    return sprintf( 
        _n('Topic: %s', 'Topics: %s', $count),
        number_format_i18n( $count )

The callback function above returns “Topic: 1” for single and “Topics: 5” for plural. Next, open your template file and use the topic_count_text_callback parameter as example below:

wp_tag_cloud( array( 
    'topic_count_text_callback' => 'my_topic_count_text' 

Now you have a custom tag tooltip. Again, modify the text and the position of %s or don’t using it all. For more parameters, you can go the the wp_tag_cloud codex documentation

Create Comment

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