Reputation: 4502
I need an script that will output only the tags text from the post tags. Not with links, ul's and other stuff, just plain text so I can add this text as a class of the post. Can anybody help? Thank you!
Upvotes: 1
Views: 4783
Reputation: 55
You can list the tags using the get_the_tag_list
method.
<?php echo strip_tags(get_the_tag_list('',' , ','')); ?>
See the WordPress Codex docs for more details.
Upvotes: -1
Reputation: 4502
Founded the answer here: need help in using get_the_tag_list($ID) WordPress
<?php
$posttags = get_the_tags();
if ($posttags) {
foreach($posttags as $tag) {
echo $tag->name . ' ';
}
}
?>
Upvotes: 3
Reputation: 11721
I needed the tag list for my meta data, here's how I assembled the string:
echo implode( ',', array_map( function( $tag ){
return $tag->name;
}, get_the_tags() ) );
this results in a comma separated tag list that can be used in the meta tags. You can remove the comma or course
Upvotes: 1