SEOify Your WordPress with Description & Keyword Meta Tags
Ever wonder how to SEOify your Wordpress install? Here’s the code I used in my Wordpress theme to use custom fields for description and keywords meta tags. The down side to using this method is that you have to modify it for any new customized meta tags you want to use. I really only wanted to customize the description and keywords meta tags, so this worked out great for me.
<?php
if (is_home()) {
$description = "Default description of this website.";
$keywords = "default, keyword, list";
} else {
$description = get_post_meta($post->ID,'description',TRUE);
$keywords = get_post_meta($post->ID,'keywords',TRUE);
}
if ($description) {
echo "\\t<meta name=\"description\" content=\"$description\" />\\n";
}
if ($keywords) {
echo "\\t<meta name=\"keywords\" content=\"$keywords\" />\\n";
}
?>
Here is another similar method:
<?php
$pagetitle = get_post_meta($post->ID,'pagetitle',TRUE);
$description = get_post_meta($post->ID,'description',TRUE);
$keywords = get_post_meta($post->ID,'keywords',TRUE);
if (empty($pagetitle)) {
echo "<title>";
wp_title('');
echo " - ";
} else {
echo "<title>";
if ($pagetitle!='') {echo "$pagetitle - ";}
}
bloginfo('name');
echo "</title>";
if (!empty($description)) {
echo "\\t<meta name=\"description\" content=\"$description\" />\\n";
}
if (!empty($keywords)) {
echo "\\t<meta name=\"keywords\" content=\"$keywords\" />\\n";
}
?>
Other meta tags, like character set, are hard coded into the main header.php code because they are the same on every page.
You can find more information about Using Custom Fields on wordpress.org. There are several meta plugins listed on wordpress.org, and a search for custom fields plugins wordpress on Google will return even more options.
Related Posts



March 2nd, 2008 at 10:51 pm
[...] SEO for WordPress blogs [...]
July 11th, 2008 at 10:45 am
Thanks a bunch, I will definately be using this :)
July 11th, 2008 at 11:46 pm
Excellent, thanks.
J.R.