WordPress.org

Ready to get started?Download WordPress

Forums

Disable automatic "echo-ing" of wp_tag_cloud() (4 posts)

  1. ritzdank
    Member
    Posted 6 years ago #

    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!

  2. ritzdank
    Member
    Posted 6 years ago #

    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 :)

  3. nigel5
    Member
    Posted 6 years ago #

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

    ob_start();
    wp_tag_cloud( $args );
    $tag_cloud = ob_get_contents();
    ob_end_clean();
  4. alexestudos
    Member
    Posted 5 years ago #

    maybe this help:
    from:
    http://codex.wordpress.org/Template_Tags/wp_tag_cloud

    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' );?>

Topic Closed

This topic has been closed to new replies.

About this Topic