I'm trying to use tags of the single post, as meta keywords.

I tried using this:

<meta name="keywords" content="<?php the_tags('',',','');?>test<?php }?>"/>

It works, but the output is:

<meta name="keywords" content="<a href="" rel="tag">aquaman</a>,<a href="" rel="tag">batman</a>,<a href="" rel="tag">wonder woman</a>"/>

Is it possible to remove the tags link/URL? And just the text/tag itself will appear?

2 Answers 2


The code is tested and working fine.

Place this code

    $posttags = get_the_tags();

    if( ! empty( $posttags ) ) :
        $tags = array();

        foreach($posttags as $key => $value){
            $tags[] = $value->name;


    <meta name="keywords" content="<?php echo implode( ',', $tags ); ?>,test"/>

<?php endif;?>

instead of

<meta name="keywords" content="<?php the_tags( '', ',', '' );?>test<?php }?>"/>
  • This is just exactly what ia needed. Thanks a lot! Apr 17, 2017 at 8:03

Use get_the_tag_list() instead of the_tags(), since the_tags() prints the results while get_the_tag_list() returns it.

See documentation: https://developer.wordpress.org/reference/functions/get_the_tag_list/

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.