Limit number of tags and display random in post content


I’m using this shortcode in post content to display tags

I’d like to limit the number of tags that are displayed.

I’d like to be able to also control whether random, asc, desc, and ideally most popular.

I’ve tried using $count but failing miserably. Alternative approach also welcome. Thanks

function getTagList($classes = '') {
global $post;
$tags = get_the_tags($post->ID);
$tagOutput = [];

if (!empty($tags)) {
    array_push($tagOutput, '<span class="tag-list '.$classes.'">');
    foreach($tags as $tag) {
        array_push($tagOutput, ''.$tag->name.', ');
        array_push($tagOutput, '</span>');
    return implode('', $tagOutput);

add_shortcode(‘tagsList’, ‘getTagList’);

Trip Vendors Inc 3 months 0 Answers 15 views 0

Leave an answer