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.

  • Mentioned in Book Review: Professional Search Engine Optimization with PHP by Sheri Bigelow of Design Simply

  • June 17, 2008 at 10:38 pm watch-street-fights

    Hi all great information here and good thread to comment on.

    Can I ask though – how did you get this picked up and into google news?

    Very impressive that this blog is syndicated through Google and is it something that is just up to Google or you actively created?

    Obviously this is a popular blog with great data so well done on your seo success..

  • July 3, 2008 at 8:52 am PHP

    Awful lot of code. Not to be rude, but I’m sure you could simplify things down a bit.

  • July 11, 2008 at 10:45 am Mike

    Thanks a bunch, I will definately be using this :)

  • July 11, 2008 at 11:46 pm J.R. Jackson

    Excellent, thanks.

    J.R.

  • August 5, 2008 at 12:53 pm Blog Hoster

    Thanks for the share.Will come in handy:)

  • September 4, 2008 at 11:45 am Ilchi Lee

    With the new release of WordPress I don’t even think this is needed anymore. Good post for those running older versions of WordPress.

  • November 28, 2008 at 7:18 pm sanji-kun

    i dont understand on the description part. is there any example on a good meta description? same goes with meta keywords. is it enough to just put on %cats% and %tags%?

  • January 24, 2009 at 8:22 pm kensty

    Great article! I’m loving your website;

  • April 11, 2009 at 3:21 am Ray Middleton

    Sorry to be off topic, but I like your posts and I wanted some feedback for my blog. I have a hard time writing, but I do want to share my experiences. Am I stuck between a rock and a hard place? Or should I just do it?

  • December 16, 2009 at 10:05 am shoudlnt i try it?

    thanx for a great post mate

  • March 8, 2010 at 6:50 am keywords software

    To be able to get the best search engine ranking you will need to do a keyword research analysis to determine what keyphrases people type in for when they are researching online. A nice keyword software will make things easier. It also helps if the niche you are researching is one that you are fanatic about.

  • April 17, 2010 at 4:23 am website promotion software?

    web marketing and advertising is undoubtedly more or less all about the range of other websites linking to you. when not having those backlinks to your site you are dead in the water. this became apparent to me soon after getting started with what is actually i think the most powerful semi-automatic one way link building tools available … promoting website

  • April 18, 2010 at 3:53 pm Rodney Navo

    It’s been a while since I scan a truly glorious blog post. Not solely well written however relevant. Congratulations.

  • April 20, 2010 at 10:50 am Bo Maker

    This is often one in all the most effective blog posts that I’ve presumably ever read. It’s like a well-written paper. Your topic has relevancy, you’ve broken the topics down logically.

  • April 21, 2010 at 8:08 pm Karma Fuhri

    Really good post. As usual…

  • April 22, 2010 at 7:43 am Rick Sartor

    Really good post. As usual…

  • April 28, 2010 at 10:12 am Kim Isidro

    i am a newbie in Search Engine Optimization but i think that the submission of articles in article directories is one of the best ways to gain backlinks. –

  • May 1, 2010 at 1:48 am Erin Turner

    WordPress is the best blogging platform ever. It is much better than Typepad and blogspot.,,~

  • May 2, 2010 at 8:01 am Web Design Consultant

    Myself I am nub in PHP but how does this code compare to the Platinum SEO Pack Plugin offered a by the WP plugin directory? Any advantages or disadvantages?

  • May 14, 2010 at 11:42 am Learn speak hindi

    good idea!

  • May 16, 2010 at 5:59 am Learn Wordpress

    I’m doing some research in this field and your post has helped a lot, thank you.

  • May 18, 2010 at 9:34 pm Ellis Gibson

    A very good marketing strategy is very important in promoting your products both online and offline.,~;

  • May 20, 2010 at 6:14 am Josh Nicholson-internet marketer

    Thanks, I’ll look into them.

  • May 24, 2010 at 7:50 pm Caden Alexander

    Copyrighting is very important specially if you wrote original articles both online and offline.

  • June 15, 2010 at 10:47 pm Trena Barness

    These kinds of posts are always inspiring, I prefer to read quality content so I pleased to find many good point here in the post, writing is simply great, thank you for the post.

  • July 30, 2010 at 10:19 pm Emily Kirby

    Worked for me thank you!

  • October 1, 2010 at 11:03 am Hanteln Kaufen

    Optimizing meta tags is important but there are a dozen plugins that do that for you, so why bother doing it yourself? Good post, though.

🎲