tags:

views:

34

answers:

3

Seems this should be super simple, but I can't find the right API function to make it work...

I'd like to use a posts tags to populate the keywords meta content...

<meta name="keywords" content="tags from post go here seperated by commas">

I've tried this but it creates a link list of each post tag...

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

+1  A: 

You need to use the template function get_the_tags to fetch the data instead of letting WordPress output it for you. You can then loop through this array and output the list however you would like:

<?php
if ( $posttags = get_the_tags() ) {
    foreach($posttags as $tag)
        echo $tag->name . ' '; 
}
?>
hansengel
Thanks hans, I appreciate the quick help!
Scott B
A: 

the_tags() automatically displays a link to each post tag. You could use get_the_tags() which returns an array of tag objects, which you can then loop through and get the name of the tag.

jackbot
+1  A: 

Try something like:

<?php
  $postTags = get_the_tags();
  $tagNames = array();
  foreach($postTags as $tag) {
    $tagNames[] = $tag->name;
  }
?>

<meta name="keywords" content="<?php echo implode($tagNames,","); ?>" />
amercader
Perfect! Thanks amercader, I just modified it slightly to test if the post has tags, otherwise it will error out...
Scott B