Where to find Malcolm Coles, reviews, and tips on how to do things I couldn’t do.

malcolm coles


Unique meta description and meta keyword tags in your Wordpress themes 13

Posted on May 26, 2008 by Malcolm Coles

Meta description tag: update

Here is the meta description PHP with both category and tag pages included (and updated again to make them more than one word and to include monthly archives):

<meta name="description" content=

"<?php

if(is_home()) {echo ('Malcolm Coles: His blog for his reviews, so you can find him, and other stuff that takes his fancy.');}

else {if(is_category()) {echo category_description();}

else {if(is_tag()) {echo '-tag archive page for this blog' . single_tag_title();}

else {if(is_month()) {echo ' archive page for this blog' . the_time('F, Y');}

else {echo get_post_meta($post->ID, "Metadescription", true);}}}}?>">

I've given up adding keywords these days! Remember, as below, you need to add a custom field called Metadescription to get this to work.

Original post about meta descriptions and keyword tags

I know little about PHP. But after fiddling round with other people's example code, I've finally managed to use custom fields to get a unique meta description and unique meta keywords on each post, and on the home page.

To get this to work, you need to add new custom fields called Metadescription and Metakeywords to each post. The ones for the home page you hard code. And I'm still working on the category pages ...

Copy and paste the code below into the head section of the header bit of your wordpress template. It basically checks if it’s the home page. If it is, it uses the hard-coded meta description and meta keywords. If it’s not, it goes and looks up the custom fields and uses the values from there. So there we have it: a unique meta description and unique meta keywords in wordpress.

Unique meta descriptions in wordpress

<meta name="description" content="<?php if(is_home()) {echo ('PUT YOUR HOME PAGE DESCRIPTION HERE');} else {echo get_post_meta($post->ID, "Metadescription", true);}?>">

Unique meta keywords in wordpress

<meta name="keywords" content="<?php if(is_home()) {echo ('PUT YOUR HOME PAGE KEYWORDS HERE');} else {echo get_post_meta($post->ID, "Metakeywords", true);}?>">

You might also like
  1. How to avoid duplicate meta descriptions in pages 2 and higher of the Wordpress loop
  2. Avoid duplicate content with paged comments in wordpress
  3. Wordpress comment pagination & duplicate content
  4. Can you use rel = canonical to fix duplicate comment problems caused by comment pagination in wordpress?
  5. Breadcrumb navigation trails and Wordpress


Share or link to this post

Trackbacks/Pingbacks

  1. Description Meta Tag Missing - No Wordpress Plugin | SEO - janet bartoli roussos
  2. How to: Create a meta description function for your WordPress blog
  3. Cómo evitar descripciones de páginas duplicadas » blogpocket
  4. 29 easy ways to fine tune your blog » malcolm coles
  5. WordPress Meta-Tags Plugin | Theme Heven
  6. 10 Custom Fields Hacks For WordPress | How-To | Smashing Magazine
  7. Custom Fields Hacks For WordPress | Fresh News - Blog Design, Wordpress, Blogger, and Web Development
  8. Custom Fields Hacks For WordPress « N3T.ir - Web Resources, Web Design News & Tips, Open Source
  9. Custom Fields Hacks For WordPress | jeremiahnellis.com/design_life
  10. Custom Fields Hacks For WordPress « Best Design Content
  11. Custom Fields Hacks For WordPress | B Studio
  12. Grumpy Git . org » Blog Archive » Custom Fields Hacks For WordPress

13 Responses to “Unique meta description and meta keyword tags in your Wordpress themes”

  1. Sumesh says:

    Some hacking there ;) but you don't have to jump through the hoops. Several plugins (eg: All In One SEO) offer this functionality and more without the hacking.

  2. Josh says:

    Thanks for posting mate and commenting on the headmeta plugin site. I was after something simple that didn't add "another plugin" to WP, something easily manageable, and this is it.

  3. Chris says:

    I've only recently started using WordPress but I was a little surprised to see that the meta description tag wasn't included as default. I suppose it could have taken the first paragraph or X characters as the text for the description but I can imagine this could create some pretty useless descriptions and you would prefer something more focused.

    I too like to dabble and have taken a similar route to yourself and added the tag in the code manually based on the page title functionality in themes/default/archive.php. I have nothing against plugins but this seemed too simple a request to require one.

    I suppose I'll have to be careful when it comes time to upgrade though but then again a plugin that works with the current version may not work after an upgrade either.

  4. A commenter says:

    Thanks, this is a great post... I improve lil bit to add meta description on tag archive, here the code:

    <?php if(is_tag()) {
    echo ''; } else {}
    ?>

    =)

  5. Samiha says:

    Great codes! Thank you very much Malcolm Coles

  6. erutrituts says:

    Отличный пост, прочитав несколько статей на эту тему понял, что всё таки не посмотрел с другой стороны, а пост как-то очень заинтересовал.

    • Courtesy of http://uk.babelfish.yahoo.com/translate_txt, this means "Outstanding post, after reading several articles on this theme he understood that all after all did not look from the other side, but post somehow greatly interested." Apparently.
      well, it did say that. When I switched host, all non-european characters got mangled. Something to do with unicode I imagine. So now it looks like gibberish

  7. Rick Upshaw says:

    I actually have the All-In-One SEO plugin installed. However, although I find it works incredibly well (and is available) for adding and editing POSTS, the plugin is nowhere to be found when I add or edit a PAGE. Does anyone know why this is, or what can be done about it? If the directions above are the only solution to this problem, then sobeit, I suppose, but if there's a way to make it work like it's supposed to, I'd like to try it.

    I am using version 1.4.6.11 of the SEO Pack, and version 2.7.1 of WordPress. The blog address is http://www.principia-college-football.org.

    Any ideas? Anyone?

  8. Jeremy says:

    Thanks for this post!

    I had figured I needed to use those custom meta fields to add the keywords and description to each page, but I just couldn't figure out the code to add to the templates.

  9. Jamal says:

    I have been searching for this code all day yesterday and finally figured out the phrase to put in the search engine and voila - up pops your site! Your instructions worked perfectly on all three of my sites! I wonder why all the theme developers don't include keywords anymore when some search engine tools still look for them.

    Thank you so much! Hopefully now people can find me on search engines.

What do you think?

All comments are moderated. Comments that include URLs and which just say 'Nice post' or similar won't be published, but thanks for the sentiment. I nearly always remove links to SEO companies, even if I publish the comment, unless it's a really interesting one.




↑ Top