So I have the default Wordpress Tag Cloud Widget on my sidebar/footer and I found the following code to limit the number that it's showing because it took up a ton of space. This code however is not actually showing the most popular tags, and I don't know what is causing this.

function set_widget_tag_cloud_args($args) {
  $my_args = array(
    'orderby'  => 'count',
    'order'    => 'DESC',
    'number'   => 15
  $args = wp_parse_args( $args, $my_args );
return $args;

So it is restricting it to 15 tags correctly, but the orderby isn't working properly. For example, my most popular tags (by count) are "Piano" and "Bells" but these are not showing on the list at all. If I run the filter without the 'number' => 15 then the orderby count works properly, but then it shows 45 tags which is too much. Once I add the number arg back into the code it restricts it to 15, but its not displaying them in the right order. enter image description here

Yellow shows tags across all limits, blue shows what tags are added upon increasing limit, red shows the top tags that don't appear under any limit, only default limit setting.

  • I tested your code in my setup and it is working as expected. – Nilambar Sharma Jun 7 '19 at 6:21
  • @Nilambar It appears to be working for me at first glance, but then when I look in admin panel, it is not corresponding to the count for the tags. If I take off the 'number' restriction then it displays the correct "Popular" tags in desc order. As soon as I put 'number' arg back, it doesn't display the top tags. Ive added links to the question to show the screenshot better displaying my issue. – pathosmusic Jun 7 '19 at 13:07

Your Answer

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

Browse other questions tagged or ask your own question.