Unique meta description and meta keywords in your Wordpress themes
Update
Here is the description with both category and tag pages included:
<meta name=”description” content=”<?php if(is_home()) {echo (’’PUT YOUR HOME PAGE DESCRIPTION HERE’);} else { if(is_category()) {echo category_description();} else { if(is_tag()) {echo single_tag_title(); } else {echo get_post_meta($post->ID, “Metadescription”, true); } } } ?> “>
Original post
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);}?>”>
on June 7th, 2008 at 6:22 pm
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.
on July 23rd, 2008 at 8:51 pm
[...] know that the default for most WordPress themes is to NOT include a META description? Why you ask? I found this blog to help sort this out and I agree with what Malcolm says. If you have ever built your blog from [...]