I am creating custom code to add schema.org markups to a page template. I wanted to echo the tags and categories as plain text to use them in the keywords and about markup fields.

I can display the tags with a code like this:

echo '<meta itemprop="keywords" content="'; echo the_tags(); echo'"/>';

but since the output is an array of link, the Google online markup test tool does not recognize the words. Also, the words have a prefix: Tags:.

My question is: is there a way to output the tags and categories of a post as plain text so I can use it inside the Schema markups that I am creating? thanks

1 Answer 1


Yes, there's many ways to do it,

You must add parameters to the function to override default value, first parameter must be empty

the_tags( '' );

echo '<meta itemprop="keywords" content="'. the_tags( '') .''"/>';

There is also wp_get_post_terms() function if you want more control,

Create a function in functions.php

function wpse_get_tags(){
   global $post;
   $term_list = wp_get_post_terms($post->ID, 'post_tag', array("fields" => "all"));
       foreach($term_list as $term_single) {
           $tags .= $term_single->name .', '; // do the job to remove last comma
     return $tags;

In your code

echo '<meta itemprop="keywords" content="''.wpse_get_tags().''"/>';

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.