Create Custom Keyword and Description Meta Tags For Your Blog

I've posted before about the excellent and versatile Get Custom Field Values WordPress Plugin
Some Useful Ideas For Custom Fields
While the purpose of this post is to show you how you can insert custom Meta Keyword Tags and Meta Description Tags into your WordPress Blog's header section, there are really quite a number of other uses as well. I use the plugin on my blogs to create multiple "excerpts" for each post and serve them on different post listing pages so that each view presents a unique description of each post. This lets me tailor different 'invitations' to read the posts and also helps to reduce identical (duplicate) content on the blogs.
I also use the plugin on some blogs to provide custom RSS feeds in sidebars on a post by post basis and to call zone sections for WPAds
Why Would You Want To Include Meta Tags With Your Posts
Well, for one thing Google actually recommends crafting Meta Description Tags in various portions of their sites like the Webmaster help section, and they make mention of the Meta Keywords Tag in ways that imply it may not be such a waste of time as some would suggest.
Putting Custom Fields To Work As Meta tags
Okay, so here's the part you're really interested in, right? How to make it happen.
First download and install the Get Custom Field Values WordPress Plugin.
Once this is installed you will want to create a custom field named "description" and another named "keywords" for each post. You can just start with new posts, or you can edit your old posts and add these custom fields.
Next you'll need to ad some code to the header.php
Here's the code as I use it on this blog.
[php]
< ?php if(is_single() || is_page()) : ?>
< ?php elseif(is_tag()) : ?>
< ?php elseif(is_category()) : ?>
< ?php else : ?>
< ?php endif; ?>
[/php]
Now lets break this down.
- Line one says if this page is a single post page or a page page we will do what is on lines 2 and 3.
- Line two calls the Get Custom Fields code and inserts it into a Meta Keyword Tag. The function c2c_get_recent_custom(); is a function that pulls out the value of a custom field. There are two functions for this. The one we are using has the _recent_ part in it's name and is for use on parts of the page outside the post loop. That means we can use it in places like the sidebar, the footer, and in this case, in the header. the 'keyword' inside the function call tells it that we want to pull out the value of the custom field named 'keyword' and the echo in front of the function call says that we want to echo the value of it to the page.
- Line three is the same as line two except that it uses the c2c_get_recent_custom(); function to call the custom field named 'description' instead of the one named 'keyword', and inserts the value into the Meta Description Tag
- Line four says if this is a 'tag' page do what is on lines five and six.
- Lines five and six use the built in WordPress Function
As of WordPress version 2.3 single_tag_title();. This echoes the actual tag name for the current tag. These lines simply insert the tag name along with some formatting text 'Posts tagged with' in the description tag in line six. - Line seven says if this is a 'category' page do what is on lines eight and nine.
- Lines eight and nine use the built in WordPress Function single_cat_title();. This echoes the actual category name for the current category. These lines simply insert the category name along with some formatting text 'Posts filed under' in the description tag in line nine.
- Line ten says if this is some other kind of page not listed above, do what is on lines eleven and twelve. These two lines simply have hard coded keyword and description text that would apply generally to the blog as a whole. If you eliminate date based pages as I do, this should only ever appear on the home page.
- Line thirteen simply ends the decision switch and says we are done figuring out what kind of page this is.
The Final Step For Custom Meta Tags On Your WordPress Blog

Scroll down to the bottom of your Post Write page in your dashboard and you'll see a form like this one. Simply type keywords in the middle text box and type in some keywords, or copy and paste your tags (as I do) to the text area on the right. Hit the "Add Custom Field Button", then typw description into the middle text box and write a short description of your post or simply copy and paste your optional excerpt (as I do) into the text area on the right.
One note before we finish. The is_tag(); function will work with WordPress version 2.3.x. It will also work with older WordPress versions, but only if you have the UTW
That's all there is to it. Each page on your WordPress blog will now have a custom Meta keyword Tag and a custom Meta Description Tag. if you have any questions or comments about this article, I'd love to hear them. Please feel free to use the comment form below, or send me a note through my contact page.
Trackback URL for this post:
Bookmark & Share: Click, Copy and Link:








Thank you for a brilliant
Thank you for a brilliant post and for all the useful and impressive information indeed. But your article needs a slight update in some aspects. When you are done, please update us with your findings.
Regards - Tina
Yes, I also like to prefer
Yes, I also like to prefer conventional seo method,
Not to jump in short while.
Kinda hard to jump from
Kinda hard to jump from classic SEO procedures to this plugin, but if it's as how it's explained, I'll give it a try and get back to you. I'm more into classical procedures though, have always been and will remain the best. They never failed me. But as I said, I'll give it a shot
All in one SEo pack is very
All in one SEo pack is very useful, I will use this plugin and AIOSP
ok, this sounds like a
ok, this sounds like a rocket science to me. But I have stumbled it anyway. ;)
PS I will probably have tons of questions about this post.
I just switched. I'm liking
I just switched. I'm liking it a lot better than All in One. Thanks!
Thanks for recommending this
Thanks for recommending this plugin. I was wondering how to do that in WP. I really noticed that Google likes well written meta description tags on my static pages.
Thanks for the tips! Really
Thanks for the tips!
Really gona use them!
@Dane-- I used to just stick
@Dane-- I used to just stick the code in. But I've learned that small one person publishers often feel uncomfortable with code. So when it can be distributed by plugin, they are more likely to apply a tip!
Not at all. I tend more
Not at all. I tend more toward sticking the code in there myself, so any time I have an idea that you think would be good to turn into a plugin, just jump on it and roll it out. ;)
Hmmm...if you don't mind, I
Hmmm...if you don't mind, I may write a plugin for the "prequel" code for users to stuff in their header. Then bloggers won't need to fiddle with their headers on their own.
Thanks Dane. One of my
Thanks Dane. One of my readers has been asking for a good plugin to create meta-tags in WP 2.3. The ones she'd found hadn't been updated.
Hi Stephen, Thanks for
Hi Stephen,
Thanks for stopping by. I really like the get custom plugin. It's just a lot simpler to use when I'm coding my themes and of course it makes grabbing data from outside the loop a breeze.
As an example I use it for dynamically populating WPAds zones based on post meta data from the custom fields and the code is just a lot easier to follow later on when I'm tweaking things out because it is obvious what I'm doing and what field I'm doing it with without having to think a lot about it.
Dane, Interesting article -
Dane, Interesting article - although personally, I use the All In One SEO plugin. Amongst other things, this gives you a field to enter Meta Keywords and Meta Description for a post and adds the tags for you (via Custom fields, but it does it for you).
I need to checkout the Get Custom Field Values plugin. I'm starting to use Custom Fields a fair bit - I normally get the information myself, ie get_post_meta($post->ID, 'customfieldname',true), but it seems the plugin can do some extra stuff. I'll be looking into it. Thanks!
Post new comment