Show most used tags in list

Most Popular Tags is a plugin that displays your blog’s most popular tags or categories as a sidebar widgetAdd the first block of code to your wordpress functions.php then add the second block of code to your wordpress theme. This will display a list of the top 10 tags by usage.

 

 

<?php
function top_tags() {
$tags = get_tags();
if (empty($tags))
return;
$counts = $tag_links = array();
foreach ( (array) $tags as $tag ) {
$counts[$tag->name] = $tag->count;
$tag_links[$tag->name] = get_tag_link( $tag->term_id );
}
asort($counts);
$counts = array_reverse( $counts, true );
$i = 0;
foreach ( $counts as $tag => $count ) {
$i++;
$tag_link = clean_url($tag_links[$tag]);
$tag = str_replace(' ', '&nbsp;', wp_specialchars( $tag ));
if($i < 11){
print "<li><a href="$tag_link">$tag ($count)</a></li>";
}
}
}
?>

<h4>Top tags</h4>
<ul>
<?php
top_tags();
?>
</ul>

Leave a comment