Post tags show outside loop?

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="http://127.0.0.1/1/tag/aquaman/" rel="tag">aquaman</a>,<a href="http://127.0.0.1/1/tag/batman/" rel="tag">batman</a>,<a href="http://127.0.0.1/1/tag/wonder-woman/" 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

<?php
    $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 }?>"/>

Leave a Comment