Last active
December 14, 2015 07:39
-
-
Save yurivictor/5052607 to your computer and use it in GitHub Desktop.
Generate meta keywords from post tags
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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