Create Custom Keyword and Description Meta Tags For Your Blog

Custom Field Data
I've posted before about the excellent and versatile Get Custom Field Values WordPress Plugin Get Custom Fields | Very Versatile WordPress Plugin is an introductory post about this plugin.. It is a wonderfully useful plugin that can do many different things throughout your blog. It's uses are literally only limited by your imagination.

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 WPAdsWPAds is a very flexible and very powerful advertisement management system for WordPress Blogs. zones on a post by post basis. It can be used to call a custom style sheet for different posts, include specific links or other texts for each post individually. There really is no limit.

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.The Google Webmaster Help Blog, Google Analytics and Google Webmaster Help Center are a few of the places where Google mentions Meta Tags and encourages their use. Now, Meta Keywords may not do a huge amount of heavy lifting for your blog, but if you could put custom keywords into each post by simply copying and pasting your tags to a new text box, then that thirty second task would have to be worth a try, right? And what about copying your custom optional excerpt (you are using that powerful feature, right?) to a second text box and having a custom meta description added to each post, again for nothing more than a thirty second investment.

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.phpThe header.php file is in your /wp-content/themes/YOURTHEMENAME/ folder. This file controls the top part of the page on your blog as well as the <head> (or Meta) section of your blog. file in your WordPress theme folder. This code will do two things. First it will check to see what kind of page your WordPress blog is currently displaying and second it will insert the proper keywords and description for that page.

Here's the code as I use it on this blog.

Note: that I do not use the <meta> </meta> syntax. I use <meta /> but the WordPress texturizer does not seem to recognize the proper way to close meta tags and inserts the meta closing tags in this sample code no matter what I try to prevent it.

[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 FunctionAs 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

Custom Fields Entry Form
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 UTWUltimate Tag Warrior. A plugin to manage tagging created by Christine Davis. This functionality is now in the WordPress Core, but before that, UTW was the Cadillac of tagging plugins. plugin installed. If you are using an older version of WordPress and you are not using UTW to handle your tagging you will want to remove that section of the code.

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:

http://danemorgan.com/trackback/58
None
Login or register to tag items
 
Posted In
Tagged With
Like this?
Bookmark & Share:
StumbleUpon Submit to Mixx Save to Google Bookmarks Save to del.icio.us
Click, Copy and Link:
<a href="http://danemorgan.com/blog/wordpress/create-custom-keyword-and-description-meta-tags-your-blog">Create Custom Keyword and Description Meta Tags For Your Blog</a>

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

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

Tina (not verified) | Fri, 06/13/2008 - 10:40

Yes, I also like to prefer

Yes, I also like to prefer conventional seo method,
Not to jump in short while.

James (not verified) | Sat, 04/12/2008 - 01:07

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

SirCommy (not verified) | Wed, 12/26/2007 - 11:28

All in one SEo pack is very

All in one SEo pack is very useful, I will use this plugin and AIOSP

Compare Hotel Prices (not verified) | Sun, 12/02/2007 - 09:58

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.

Vlad (not verified) | Mon, 11/26/2007 - 02:29

I just switched. I'm liking

I just switched. I'm liking it a lot better than All in One. Thanks!

Chris B. (not verified) | Sun, 11/25/2007 - 15:35

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.

Cheap Web Hosting (not verified) | Fri, 11/23/2007 - 10:34

Thanks for the tips! Really

Thanks for the tips!
Really gona use them!

Francisco Costa (not verified) | Sat, 11/17/2007 - 21:01

@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!

Lucia (not verified) | Mon, 11/12/2007 - 10:28

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

Dane (not verified) | Sun, 11/11/2007 - 09:41

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.

Lucia (not verified) | Sun, 11/11/2007 - 09:35

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.

Lucia (not verified) | Sun, 11/11/2007 - 09:31

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 (not verified) | Thu, 11/08/2007 - 21:13

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!

Stephen Cronin (not verified) | Mon, 11/05/2007 - 22:42

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
  • Restrict text by wrapping in [restrict:roles=<comma separated roles>] and [/restrict]
  • Links to specified hosts will have a rel="nofollow" added to them.

  • Highlight terms in this textarea.
  • You can enable syntax highlighting of source code with the following tags: <code>, <blockcode>. Beside the tag style "<foo>" it is also possible to use "[foo]".
  • Use <fn>...</fn> to insert automatically numbered footnotes.
  • You may link to webpages through the weblinks registry

More information about formatting options

CAPTCHA
Please fill out this captcha to demonstrate your humanity.
7 + 6 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.