Design Simply

Simplicity in design, photography & code.


SEOify Your WordPress with Description & Keyword Meta Tags

Ever wonder how to SEOify your Wordpress install? Here’s the code I used in my Wordpress theme to use custom fields for description and keywords meta tags. The down side to using this method is that you have to modify it for any new customized meta tags you want to use. I really only wanted to customize the description and keywords meta tags, so this worked out great for me.

<?php
if (is_home()) {
   $description = "Default description of this website.";
   $keywords = "default, keyword, list";
} else {
   $description = get_post_meta($post->ID,'description',TRUE);
   $keywords = get_post_meta($post->ID,'keywords',TRUE);
}
if ($description) {
   echo "\\t<meta name=\"description\" content=\"$description\" />\\n";
   }
if ($keywords) {
   echo "\\t<meta name=\"keywords\" content=\"$keywords\" />\\n";
   }
?>

Here is another similar method:

<?php
  $pagetitle = get_post_meta($post->ID,'pagetitle',TRUE);
  $description = get_post_meta($post->ID,'description',TRUE);
  $keywords = get_post_meta($post->ID,'keywords',TRUE);
  if (empty($pagetitle)) {
    echo "<title>";
    wp_title('');
    echo " - ";
  } else {
    echo "<title>";
    if ($pagetitle!='') {echo "$pagetitle - ";}
  }
  bloginfo('name');
  echo "</title>";
  if (!empty($description)) {
    echo "\\t<meta name=\"description\" content=\"$description\" />\\n";
  }
  if (!empty($keywords)) {
    echo "\\t<meta name=\"keywords\" content=\"$keywords\" />\\n";
  }
?>

Other meta tags, like character set, are hard coded into the main header.php code because they are the same on every page.

You can find more information about Using Custom Fields on wordpress.org. There are several meta plugins listed on wordpress.org, and a search for custom fields plugins wordpress on Google will return even more options.

Add to your del.icio.us Add to del.icio.us Digg this storyDigg this

One Response to “SEOify Your WordPress with Description & Keyword Meta Tags”

  1. Book Review: Professional Search Engine Optimization with PHP by Sheri Bigelow of Design Simply Says:

    [...] SEO for WordPress blogs [...]

Leave a Reply



Copyright © 2000-2008 Sheri Bigelow. Proudly powered by WordPress and hosted by bluehost.
Log in. Valid XHTML 1, CSS 2. Entries (RSS) and Comments (RSS).