Skip to content

Instantly share code, notes, and snippets.

@yurivictor
Last active December 14, 2015 07:39
Show Gist options
  • Save yurivictor/5052607 to your computer and use it in GitHub Desktop.
Save yurivictor/5052607 to your computer and use it in GitHub Desktop.
Generate meta keywords from post tags
<?php
/**
* Generate meta keywords from post tags
*
* @uses wp_get_post_tags
* @return string keywords
*
* Usage:
* <meta name="keywords" content="<?php echo get_meta_keywords(); ?>">
*/
function get_meta_keywords() {
global $post;
$keywords = wp_get_post_tags( $post->ID );
$total = count( $keywords );
$count = 1;
$keys = '';
foreach ( $keywords as $keyword ) {
$keys .= $keyword->name;
if ( $count != $total ) {
$keys .= ', ';
}
$count++;
}
return $keys;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment