How to properly get only e.g. 3 post tags? My current code:
$post_tags = get_the_tags();
if (!empty($post_tags)) {
foreach ($post_tags as $tag) {
echo '<a href="' . get_tag_link($tag->term_id) . '">' . $tag->name . '</a>';
}
}
Your question seems similar to this one: how to limit and display tag?
Based on it you can use this code to limit the tags:
$post_tags = get_the_tags();
shuffle($post_tags); // use this incase you want to pick the tags randomly
$count = 0;
if ($post_tags) {
foreach($post_tags as $tag) {
$count++;
echo '<a href="'.get_tag_link($tag->term_id).'">'.$tag->name.'</a> ';
if( $count > 4 ) break;
}
}
It will return 3 tags only.