Adrian Florescu
Adrian Florescu

Reputation: 4502

Wordpress - get_the_tag_list - only text!

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

Answers (3)

cRiSs rOcCa
cRiSs rOcCa

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

Adrian Florescu
Adrian Florescu

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

patrick
patrick

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

Related Questions