In this post lets start for how to show limited number of tags when after post in your WordPress Theme.
Actually when we are posting new article in the posts and we adding also number of few tags in the post but in our designing part we want to show limited or one number of tags not to all, So here in this article you can get some idea about how we can limit number of posts tags.
First of all you need to open your theme’s functions.php file and add this code.
function show_limit_two($terms) {
return array_slice($terms,0,2,true);
}
Note: You can change the 2 number to maximum count per your needs.
Now add this code inside your designing part wherever you want.
<?php the_tags() ?>
The code above will show number of 2 limit tags, if you want to less or more tags then just change the number 2 or add this code elsewhere inside your designing section and customize the code.
$count=1;
if ($posttags) {
foreach($posttags as $tag) {
$count++;
echo ”
“;
if( $count > 1 ) break;
}
}
else {
echo ”
“;
}
?>
The above code will be display 1 tags in the theme or designing on your part. If you want to show less tags or more tags, simply adjust the $count > 1 line with the number how you want.
In the end
I hope you have found this article helpful. Let us me your opinion or questions if any through the comment form in below or use this form to ask your question.