Limit number of tags and display random
Question
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’);
0
3 months
0 Answers
15 views
0
Leave an answer
You must login or register to add a new answer .