• Skip to main content
  • Skip to secondary menu
  • Skip to primary sidebar
  • Skip to footer
  • PSD to Genesis
  • Personalized Genesis Child Theme
  • Custom Website
  • Rainmaker
  • Genesis Customizations

Christoph Herr

Solutions For Your Online Business

  • Home
  • Articles
  • Recommendations
  • About
  • Praise
  • Contact
  • Schedule a Call

How to show the Tag Cloud widget as a list in WordPress 4.4

Last updated on February 13, 2016 by Christoph Herr Leave a Comment

The question came up on the Studiopress forum, how to show the Tag Cloud widget as a list in WordPress 4.4 ( showing only the tags of a single post) after previous code stopped working as expected after the update.

Adjusting the output of the tag cloud started breaking the HTML markup, most notably the Widget title is no longer displayed.

This is an example of code that was working before updating to WordPress 4.4

add_filter( 'widget_tag_cloud_args','single_post_tag_cloud_tags' );
/**
 * Output the tag_cloud only with tags of the single post as a list]
 * @param    array $args    Display arguments.
 * @return array Settings for the output.
 */
function single_post_tag_cloud_tags($args) {

        global $post;
        $post_tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
        $args = array(
                    'include' => implode( ',',$post_tag_ids ),
                    'largest' => 12,
                    'smallest' => 12,
                    'format' => 'list',
                );
        return $args;
}

 

Used in WordPress 4.4 it shows the following:

Tag Cloud Widget as a list in WordPress 4.4 breaking markup and without widget title

What happened?

WordPress made a change in the way it outputs the arguments of wp_tag_form in Version 4.4 (see https://core.trac.wordpress.org/changeset/34273).

Behind the scenes the arguments are output before the markup is ready.

We have to somehow improve the timing and “slow down” the execution of our code.

Enter wp_parse_args. We can use this function to merge our changes (custom arguments) with the default values instead of overriding them.

The code needs just a few changes:

add_filter( 'widget_tag_cloud_args', 'single_post_tag_cloud_tags' );
/**
 * Output the tag_cloud only with tags of the single post as a list]
 * @param array $args Display arguments.
 * @return array Settings for the output.
 */
function single_post_tag_cloud_tags($args) {

        global $post;
        $post_tag_ids = wp_get_post_tags( $post->ID, array( 'fields' => 'ids' ) );
        $ch_args = array(
                    'include' => implode( ',',$post_tag_ids ),
                    'largest' => 12,
                    'smallest' => 12,
                    'format' => 'list',
                );
        $args = wp_parse_args( $args, $ch_args );
        return $args;
}

 

This is the result on the website

Tag Cloud widget as a list in WordPress 4.4 with widget title and good markup

 

 

References:

https://core.trac.wordpress.org/changeset/34273

https://wordpress.org/support/topic/wordpress-44-update-broke-tag-cloud#post-7767763

Share this:

TwitterFacebookPinterestLinkedInEmail

Filed Under: Code Snippets

Reader Interactions

Leave a Reply Cancel reply

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

Primary Sidebar

Getresponse Email Marketing WordPress Speed Test

Subscribe to my newsletter

Please enter your information here:

I hate spam. Your information is save.

Latest Posts

WordPress Black Friday & Cyber Monday Deals

Once again it´s time for WordPress Black Friday & Cyber Monday Deals. Like last year, I have … [Read More...] about WordPress Black Friday & Cyber Monday Deals

Cafe Pro - sticky menu and image logo - end result

Add a logo to the sticky menu of Cafe Pro

A member of the Studiopress forum asked how to show a logo in the after header menu (primary … [Read More...] about Add a logo to the sticky menu of Cafe Pro

Smart Passive Income Pro screenshot

Remove the featured image from the homepage of Smart Passive Income Pro

Studiopress just released a new child theme for the Genesis Framework, called Smart Passive Income … [Read More...] about Remove the featured image from the homepage of Smart Passive Income Pro

Footer

StudioPress Theme of the Month

Copyright © 2021 · Magazine Pro Theme On Genesis Framework · WordPress · Log in