More than 800+ satisfied clients and counting, since 2010


Building better tag clouds in WordPress

When the tag definition for the WordPress site or blog is done, all you need to think about next is to set a tag cloud in any places of the template. You need to use the function wp_tag_cloud() or the function wp_generate_tag_cloud(). Following the existing method, you may be contended with yourself, but there are things to explore too. Inline styles are too old and most of them stopped using it in 1998. The ID is fragile in the current method and an URL that is complete is required. Of course, you can expect more control, even though wp_tag_cloud(). You can add five to six classes of tags. So, it is better to go for a PHP function. You get the results of a customized tag cloud. You can place this in the plugins or in the contents file. Read through to know more on building better tag clouds in WordPress. Use this code to get a name and array of number arguments:

//generate tag cloud

Function My_TagCloud($params=array()){



‘order’ => ‘ASC’,


‘wrapper’ => ‘’,

‘sizeclass’ => ‘tagged’,

‘sizemin’ => 1,

‘sizemax’=> 5

), $params));

Now, initialize the HTML returns.


$ret = ‘’;

$min = 9999999; $max = 0;

Now, the get_tag() function is started to return the array of subject;

//fetch all wordpress tags

$tags = get_tags(array(‘orderby’ =>$orderby, ‘order’ => $order, ‘number’ => $number))

To know the minimum and maximum number of tags used:

//get minimum and maximum number tags

Foreach ($tags as $tag) {

$min = min($min, $tag->count);

$max = max($max, $tag->count);


To generate the tag list:

Foreach ($tags as $tag) {


$title = $tag->count. ‘article’. ($tag->count == 1? ‘’:’s’);

With all these codes, the HTML tag and end of loop can be created:


($wrapper ?<”wrapper”> ;”

<’a href=\”$url\” class=\”title=\”$title\”>{$tag->name}</a>”.

($wrapper? “</$wrapper>” : “);

To enable short code:

Add_shortcode(‘tagcloud’, My_TagCloud);

Written by

The author didnt add any Information to his profile yet