Internet
How to
Newspapers
Twitter
SEO advice
Categories: Wordpress. Tags: ,

Unique meta description and meta keyword tags in your WordPress themes

May 26, 2008 38 Comments

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. Adding page numbers: How to avoid duplicate titles and meta descriptions in pages 2 and higher of WordPress category and tag pages
  2. Ignore WordPress’s SEO advice
  3. Avoid duplicate content with paged comments in wordpress
  4. WordPress comment pagination & duplicate content
  5. Meta keywords tag: Bing says carry on but Google says it’s a waste of time – but

Share this post

Follow me on Facebook or Twitter

38 Comments »

Leave a comment!

Add your comment below, or trackback from your own site. You can also subscribe to these comments via RSS.

Be nice. Keep it clean. Stay on topic. No spam.

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

This is a Gravatar-enabled weblog. To get your own globally-recognized-avatar, please register at Gravatar.