Unique meta description and meta keyword tags in your Wordpress themes 13
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
- How to avoid duplicate meta descriptions in pages 2 and higher of the Wordpress loop
- Avoid duplicate content with paged comments in wordpress
- Wordpress comment pagination & duplicate content
- Can you use rel = canonical to fix duplicate comment problems caused by comment pagination in wordpress?
- Breadcrumb navigation trails and Wordpress


This is the personal blog of Malcolm Coles.
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.
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.
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.
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 {}
?>
=)
Your PHP seems to have been eaten... But no worries as my code above already generates a meta description for tag pages.
Great codes! Thank you very much Malcolm Coles
Отличный поÑÑ‚, прочитав неÑколько Ñтатей на Ñту тему понÑл, что вÑÑ‘ таки не поÑмотрел Ñ Ð´Ñ€ÑƒÐ³Ð¾Ð¹ Ñтороны, а поÑÑ‚ как-то очень заинтереÑовал.
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
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?
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.
Well, you're using all in one SEO pack, so you could probably just use that ... I'll give you the benefit of the doubt and let you keep the link
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.