This post is also available in:
Português
In this blog post, we’ll discuss how to customize the WordPress Tag Cloud widget, a valuable feature that showcases a collection of your most frequently used tags on the sidebar or other widget-supporting areas of WordPress-powered websites. However, as the number of tags increases, the list generated by the Tag Cloud widget may become too lengthy or too brief for your preference.
The Standard Tag Cloud Widget
Regrettably, the default Tag Cloud widget does not offer the option to limit or expand the tag count. The default count is 45.
To tailor the number of tags displayed by the Tag Cloud widget, there is currently no direct method provided. Instead, you can include the following code snippet in your active theme’s functions.php custom functions file to exert control over the tag count:
/*********************************************************
* Adjust the tag count displayed by the Tag Cloud widget *
*********************************************************/
add_filter( 'widget_tag_cloud_args', 'mz_tag_cloud_limit' );
function mz_tag_cloud_limit($args){
// Verify if the widget's taxonomy option is set to tags
if ( isset($args['taxonomy']) && $args['taxonomy'] == 'post_tag' ){
$args['number'] = 25; // Set the number of tags to display
}
return $args;
}
Substitute the tag count in the code with your preferred number. The example above shows 25 tags. By default, WordPress displays up to 45 of the most frequently used tags. You can increase or decrease this number as needed.
If you utilize custom taxonomies and want to showcase them instead of the default tags, replace the post_tag (the standard WordPress taxonomy for tags) in the provided code with the custom taxonomy term.







Comentários Recentes