Last Updated on 2022-01-01 by Clay
I am very accustomed to using tags to highlight which topics are included in my articles. Naturally, there are widgets like tag cloud on the sidebar of my website.
For a long time, I have been concerned that some tags are not displayed in the tag cloud; at first, I was not sure why, but after some searching, I realized that the original WordPress tag cloud only displays 45 tags by default.
So how do we edit the display number? Some admin user can use graphical interface to change, but I do not have it. I need to edit the functions.php file in theme folder.
Change the tag cloud display number limitation steps
Go into the website backend, according public_html > wp-content > themes > YOUR_THEME > functions.php you can find the file we need to edit, and add the following code in the tail.
// Fixed the tag cloud size
add_filter( 'widget_tag_cloud_args', 'change_tag_cloud_font_sizes');
/**
* Change the Tag Cloud's Font Sizes.
*
* @since 1.0.0
*
* @param array $args
*
* @return array
*/
function change_tag_cloud_font_sizes( array $args ) {
$args['smallest'] = '12';
$args['largest'] = '12';
$args['number'] = 0;
return $args;
}
I have written this function before, originally to fix the size of the label. The most important thing now is to add $args['number'] = 0;
this line. If you set it to 0, all labels will be displayed. If you set an integer it will be the maximum number displayed.
Set to 0
Set to 15
References
- https://wordpress.stackexchange.com/questions/155206/edit-tag-cloud-widget-number
- https://wordpress.com/support/widgets/tag-cloud-widget/#:~:text=Number%20of%20Tags%3A%20The%20maximum,cloud%20(up%20to%2075).