using get_sites I managed to display a list of WP Multisite Subsites with a variety of data pulled from the sites. However I cannot control where the tags are being displayed -- instead of showing up within the html elements, a tag cloud is displayed above the page content

/** get sites */

function make_list_shortcode()
$subsites = get_sites (
['number' => 500, 'orderby' => 'last_updated', 'order' => 'DESC', ]);
if (!empty($subsites))
    $html = '<ul >';
    foreach($subsites as $subsite)
        $subsite_id = $subsite->blog_id;
        $subsite_name = get_blog_details($subsite_id)->blogname;
        $subsite_link = get_blog_details($subsite_id)->siteurl;
        $subsite_domain = get_blog_details($subsite_id)->domain;
        $subsite_path = get_blog_details($subsite_id)->path;

// Switch to Blog
        switch_to_blog( $subsite->blog_id );
        $site_description = get_bloginfo( 'description' );
        $logo_image = get_theme_mod( 'fl-logo-image' );
        $custom_header = get_theme_mod( 'header_image' );
        $tags = wp_tag_cloud( array( 'taxonomy' => 'category' ) );

        // Added the image tag and src path
        $html.= '<li style="list-style: none!important; margin:10px 0; padding:10px; border: 1px solid #ccc;" class="site-' . $subsite_id . '" ><a href="' . $subsite_link . '" target="_blank"><img style="margin-right: 15px;" src="'. $logo_image .'" /><img style="margin-right: 15px;" src="'. $the_custom_logo .'" /><img style="margin-right: 15px;" src="'. $custom_header .'" />' . $subsite_name . '</a> ' . $site_description . ' '. $tags .'</li>';


    $html.= '</ul>';
    return $html;

add_shortcode('list_sites', 'make_list_shortcode'); 

The result is pulling tags from the subsite but also ignoring $tags in the html element completely.

I also have another question about how to insert an if function exists for the = get_theme_mod in looking for images - different themes use different methods and the way I have it generates 404 errors.

Truly appreciate any help.


wp_tag_cloud() will echo the tags by default. Because this happens before your return $html; line, the cloud gets displayed above the shortcode content.

To prevent this, set the echo arg to false:

$args = array(
    'taxonomy' => 'category',
    'echo'     => 'false',
$tags = wp_tag_cloud( $args );
  • Thanks Pat J, I ended up getting this to work $tags = wp_tag_cloud( array('taxonomy' => 'category', 'echo' => 0) ); FYI for those interested I also added <base target="_blank"> to the head of the page to get all links to open new window. BTW the last argument in a list like that should not have the period. Still struggling with figuring out if exists statements if anyone can help... thanks – Trip Vendors Inc Sep 15 '18 at 5:32
  • 1
    For the if ( function_exists( ... ) ) question, you should ask a new question. – Pat J Sep 15 '18 at 23:22

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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