WordPress Keywords and Description Meta Tags

// December 21st, 2009 // Useful Code

The code below allows you to add keywoards and description meta tags to any wordpress theme. Simple copy the below code and insert it into the header.php of your theme somewhere inside of the <head></head> tag.

You could also simply download the plugin I wrote for this as well. Although I have submitted it to WordPress.org they have not posted it yet so here is a link in the mean time. Please note the plugin is a little more customizable then the code below.

-Auto Keywords and Description Generator-

//Code


<?php
$keywords = "";
$description = "";
	
if(is_home() || is_front_page())
{
	//LOAD KEYWORDS FROM USER SPECIFIED STRING
	$keywords = "Insert your homepage keywords here";

	//LOAD DESCRIPTION FROM BLOGINFO
	$description = bloginfo('description');
}
elseif(is_single())
{
	//LOAD POST TITLE AS DESCRIPTION
	$description = $post->post_title;
	
	//BUILD LIST OF KEYWORDS FROM TAGS
	$tags = wp_get_post_tags($post->ID);
	foreach($tags as $tag)
		$keywords = $keywords . $tag->name . ", ";
}
elseif(is_category())
{
	//LOAD CATEGORY DESCRIPTION
	$keywords = single_cat_title('', false);
	$description = category_description();
}
?>
<meta name="keywords" content="<?php echo $keywords ?>" />
<meta name="description" content="<?php echo $description ?>" />
Be Sociable, Share!
  • RSS
  • Twitter
  • Facebook
  • LinkedIn
  • DeviantArt