function hashtags(){
$tags = get_the_tags($post->ID);
$count=0;
foreach ($tags as $tag){
$count++;
if (1 == $count) {
return $tag->name . ', ';
}
if (2 == $count) {
return $tag->name . ', ';
}
if (3 == $count) {
return $tag->name;
}
}
}
I don’t know about php, i’m noob, i made this function for showing the name of the first 3 tags of post, i want this return: tag1, tag2, tag3.
The function works but only return the first tag, if i put echo no problem but i don’t want an echo, any idea?
Sorry if I’ve misunderstood but I think you’re trying to return a comma separated list of the names found by the
get_the_tagsfunction? If so this should work:That code loops through the tags, adds each tag name to an array (
$names), and finally runs the array throughimplode()to generate the comma separated list.