I am using this code to get the tags in my wordpress posts for a theme
`<?php
$posttags = get_the_tags();
if ($posttags) {
foreach ($posttags as $tag) {
$tagnames[count($tagnames)] = $tag->name;
}
$comma_separated_tagnames = implode(", ", $tagnames);
print_r($comma_separated_tagnames);
}
?>`
The PROBLEM is that it is returning tags for “all posts” not just individual posts, and I think the problem is that if a post DOESNT have tags – it just inserts tags anyway.
Can anyone help modify this so:
- It return tags only for a post – not all tags
- If there are no tags for a post, dont return anything
This is what I did, displays tags for each post in the loop.
Try using:
Inside the ‘Loop‘.
Function Reference
alright I hope this could help someone , I stuck on this issue for about hour
trying to get tags of my post “so I can mix it with twitter share link ”
the_tags(); function were useless since I use it out of WP loop , get_the_tag_list(); were perfect to me since it can include post id ,
^^ the above code I stripped html codes to get tag name without href link .
this is the function use case :-