WordPress – How to limit tag cloud widget to 20 items

The following WordPress PHP function will automatically limit the tag cloud widget list to 20 items.

The number of items can be changed by adjusting the ‘number’ argument.

The code also removes the white space separator.

If you’re not sure where to place this code I highly recommend you read How to create a WordPress plugin for your custom functions.

// limit cloud tag widget to 20, and remove white space separator

add_filter( 'widget_tag_cloud_args', 'itsg_limit_tag_cloud_widget_list', 10, 2 );

function itsg_limit_tag_cloud_widget_list( $args, $instance ) {
     $args['number'] = 20;
     $args['separator'] = "";
     return $args;