/* Plugin Name: Add Meta Keyword Tag Plugin URI: http://www.projectarcanum.com/archive/2006/03/05/wordpress-plugin-add-meta-keyword-tag/ Description: Outputs meta keyword tags. For single posts it can create keywords from categories names or Bunny's Technorati Tags (or any custom field with keywords/tags). Version: 1.0 Author: Cody Williams Author URI: http://www.projectarcanum.com/ Copyright (c) 2006 Cody Williams Released under the GNU General Public License (GPL) http://www.gnu.org/licenses/gpl.txt */ /* Settings */ $use_categories = true; // use category names as keywords $categories_first = true; // categories go first in keyword list. set to false to put categories after tags $use_bunny = true; // use Bunny's Technorati Tags as keywords, or basically any custom field with seperated tags $single_only = true; // set to true to only output keywords on single posts. $defaultkeywords = 'your, keywords, here'; // if $single_only is false, these keywords will be output on any page that is not a single post. /* More Advanced Settings */ $bunny_custom_field = 'tags'; // the custom field of you bunny tags, by default is 'tags'. $bunny_tag_seperator = ' '; // the tag seperator that seperates tags in the custom field. In Bunny's tags this defaults to space /* End Settings */ function add_meta_keyword_tag() { global $use_categories, $categories_first, $use_bunny, $bunny_custom_field, $bunny_tag_seperator, $defaultkeywords, $single_only, $posts; $keywords = ''; if (is_single()) { if (($use_categories) and ($categories_first)) { // create keywords from categories $categories = get_the_category($posts[0]->ID); $categorycount = count($categories); $count = 1; foreach( $categories as $cat ) { if ($count == $categorycount) { // last one, dont need a seperator $keywords .= $cat->category_nicename; } else { $keywords .= $cat->category_nicename . ', '; } $count = $count + 1; } } if ($use_bunny) { // create keywords from Bunny's Technorati Tags or something similair $gettags = get_post_custom($posts[0]->ID); $tags = $gettags[$bunny_custom_field][0]; if(!empty($tags)) { if (($categories_first) and ($use_categories)) { $keywords .= ', '; } $tags = str_replace($bunny_tag_seperator,', ',$tags); $keywords .= $tags; if (!($categories_first) and ($use_categories)) { $keywords .= ', '; } } } if (($use_categories) and !($categories_first)) { // create keywords from categories $categories = get_the_category($posts[0]->ID); $categorycount = count($categories); $count = 1; foreach( $categories as $cat ) { if ($count == $categorycount) { // last one, dont need a seperator $keywords .= $cat->category_nicename; } else { $keywords .= $cat->category_nicename . ', '; } $count = $count + 1; } } } else { if (!($single_only)) { $keywords = $defaultkeywords; } } // output meta keyword tag echo '' . "\n"; } add_action('wp_head', 'add_meta_keyword_tag'); ?>