Get the most recent tags in WordPress (Shortcode)

Update: Better one here (MySQL)

If you want to display the most recent tags in WordPress, apply this code to the current theme’s functions.php

function most_recent_tags($args){

 $limit = 10; //limit 10 tags by default
//Get limit tags argument from shortcode
 $numargs = func_get_args();
 if (isset($numargs['limit']) && filter_var($numargs['limit'], FILTER_VALIDATE_INT)){
    $limit = $numargs['limit'];

    'number'     => $limit,   
    $tags = get_tags($args);
    $trend_tags_html = '<div class="post_tags">';
    foreach ( $tags as $tag ) {
    $tag_link = get_tag_link( $tag->term_id );

    $trend_tags_html .= "<a href='{$tag_link}' title='{$tag->name} Tag' class='{$tag->slug}'>";
    $trend_tags_html .= "{$tag->name}</a>";
    $trend_tags_html .= '</div>';

    return $trend_tags_html; 


In my case, I will get 20 most recent tags by using the shortcode:

[most_recent_tags limit=20]

Leave a Reply

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

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>