Simplicity in design, photography & code.

Tiny Colorslogo.gifVoodoo DoughnutNutella crepeDJs at InstantChess PiecesCurious FriendSara and NoraTriborough Bridge from AstoriaMorning CoffeeWhat to do?

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.

28 Responses to SEOify Your WordPress with Description & Keyword Meta Tags

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

  2. 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..

  3. PHP says:

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

  4. Mike says:

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

  5. J.R. Jackson says:

    Excellent, thanks.

    J.R.

  6. Blog Hoster says:

    Thanks for the share.Will come in handy:)

  7. Ilchi Lee says:

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

  8. sanji-kun says:

    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%?

  9. kensty says:

    Great article! I’m loving your website;

  10. 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?

  11. shoudlnt i try it? says:

    thanx for a great post mate

  12. 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.

  13. 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

  14. Rodney Navo says:

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

  15. Bo Maker says:

    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.

  16. Karma Fuhri says:

    Really good post. As usual…

  17. Rick Sartor says:

    Really good post. As usual…

  18. Kim Isidro says:

    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. -

  19. Erin Turner says:

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

  20. 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?

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

  22. Ellis Gibson says:

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

  23. Thanks, I’ll look into them.

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

  25. 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.

  26. Emily Kirby says:

    Worked for me thank you!

  27. 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.

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>