Support » Developing with WordPress » Disable automatic “echo-ing” of wp_tag_cloud()

  • Hi all,

    Is there a way of disabling the automatic echo of the function wp_tag_cloud()? I would like to make some regular expression, but i can’t assign it to a variable.

    For example: wp_list_categories(‘echo=0’) features the “silent” method! So, you can assign it like $lists = wp_list_categories(‘echo=0’) .. but tag_cloud echoes automatically!!

    Any hacks for wp_tag_cloud()?

    Thank you so much!

Viewing 3 replies - 1 through 3 (of 3 total)
  • Found a solution thanks to the guys in IRC channel 🙂

    copy from wp-include/widgets.php following function into your themes/default/functions.php

    function wp_tag_cloud( $args = '' ) {

    rename the function, for example get_tag_cloud (…..

    and change last line in that function from “echo” to “return”

    return apply_filters( 'wp_tag_cloud', $return, $args );

    Works 🙂

    or if you don’t want to tweak the core code, you can use ob_start()…

    wp_tag_cloud( $args );
    $tag_cloud = ob_get_contents();


    maybe this help:

    Cloud returned as array but not displayed
    The variable $tag will contain the tag cloud for use in other PHP code
    <?php $tag = wp_tag_cloud('format=array' );?>

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Disable automatic “echo-ing” of wp_tag_cloud()’ is closed to new replies.