Home / tags / Show most used tags in list
  • How to Show most used tags in list

    no thumbnail sorry: Show most used tags in list

    Add 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.

    ( click code to copy )

    wordpress snippet : PHP -functions.php

    <>
    <?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>";
    		}
    	}
    }
    ?>
    
    ( click code to copy )

    wordpress snippet : PHP - theme

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

    ( WordPress codex functions, hooks, in this snippet. )

    tag_link, get_tag, get_tag_link, get_tags, clean_url, wp_specialchars, wp,
  • Lian00

    Hello, nice function. I need to show the total of  posts for each tag. How to do it with your function ?

    • Lian00

      Sorry, it was already in your function !

      • No problem, glad you like the snippet. 

        • Maposee Soleh

          possible to remove a count number on the end of tags, how to do that

  • Hassan

    thank you very my dear friend

  • Hassan

    much*