Change title attribute in tagcloud links (4 posts)

  1. Hans Christian Rodríguez
    Posted 3 years ago #


    I want to edit the title attribute in the tagcloud links that now shows the count of post inside each tag ("x topics").

    <a href="URL" class="tag-link-39" title="2 topics">Bangladesh</a>

    I've found some people in Google who offer this BAD solution:


    But I don't want modify the category-template.php file, I think there will be another way to fix this with a plugin or functions.php code.

    Thank you so much : )

  2. vjpo
    Posted 3 years ago #

    The example for functions.php that customising TC widget

    // prepare a topic count text
    function my_default_topic_count_text( $count ) {
        return sprintf( _n('%s article', '%s articles', $count), number_format_i18n( $count ) );
    // customise the tag cloud widget
    function my_tag_cloud_args($in){
        return 'topic_count_text_callback=my_default_topic_count_text';
    add_filter('widget_tag_cloud_args', 'my_tag_cloud_args' );

    you can edit other parameters of the tag cloud widget according to codex. e.g.

    for customising hardcoded wp_tag_cloud you need only to call your custom function for topic_count_text_callback in arguments. (do not use filter for widget_tag_cloud_args)

  3. Hans Christian Rodríguez
    Posted 3 years ago #

    Thank you so much, Vjpo.

    I'm trying to understand and doing tests in my site with your code solution, but I don't have enough php skills (I'm designer) to understand you or the Codex solution :-(

    I've added the first code block to my functions.php but I don't know how use these parameters to customize the title.

    Can you or anyone reading us be more specific? Thank you already for helping, Vjpo! : )

  4. vjpo
    Posted 3 years ago #

    Hi Hans! If you will clarify what text must be instead "x topics" and what kind of tag cloud do you use (default Tag Cloud widget or function wp_tag_cloud in theme code), I perhaps will be able to modify this function.

Topic Closed

This topic has been closed to new replies.

About this Topic