Shorten long tags in widget “tag cloud”

I’m using a slightly customized tag cloud (default WordPress widget; see below for my current code).

Some tags in my cloud are quite long, because I changed their taxonomy page for SEO reasons by adding a more descriptive name.

When these tags are displayed in the tag cloud, it destroys my layout. So I’m looking for a way to display shorter versions of long tags.

I have two ideas in mind:

(a) Set a maximum length for tags, e.g. “sampleTagVeryLoooooong” -> “sampleTagV…”

or

(b) use the slug (part of the URL) instead of the full name. In this case, “-” char needs to be replaced by a space for better human readability.

Basically I would prefer (a), because second solution removes German umlauts and other special characters not allowed in URL format.

My current modifications for your reference:

remove_filter(‘widget_tag_cloud_args’, ‘mh_magazine_custom_tag_cloud’, 11);
function mh_magazine_custom_tag_cloud( $args ) {
$args[‘number’] = 13;
$args[‘largest’] = 14;
$args[‘smallest’] = 10;
$args[‘unit’] = ‘px’;
return $args;
}
add_filter( ‘widget_tag_cloud_args’, ‘mh_magazine_custom_tag_cloud’ );

Any help is highly appreciated !

Read more here:: Shorten long tags in widget “tag cloud”

Leave a Reply

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