Your Ad Here

Autogenerate WordPress META Tags

META tags list information about the page, such as the author, keywords, description, etc. META tags appear in the HTML header of a webpage located between <HTML> and </HTML>. For more information about META tags and other HTML header properties visit the W3C page on html structure. In short, these tags are important because they provide information about your website to bots such as the all important googlebot . In fact, the use of META tags is probably the oldest and simplest way of helping bots gather information about your site.

The title and description META tags

While WordPress doesn’t add META tags automatically (why? — I have no idea) the official WordPress support website contains this page explaining how to easily add the meta tag for the title and description of your wordpress site. In short you simply have to add the following lines of code to your header.php file of your wordpress theme.

<meta name="description" content="<?php if ( is_single() ) {
single_post_title(”, true);
} else {
bloginfo(‘name’); echo " – "; bloginfo(‘description’);
}
?>" />

Easy, right? Well now comes the hard part…


The keywords META tag

I was actually surprised that WordPress support didn’t give any means of automatically adding this important line to the HTML header. Well, if you are using the ‘jack-of-all-tags’ Ultimate Tag Warrior (UTW) plugin then you are in luck (sort of). UTW will output a nice comma separated list of tags for you using the UTW_ShowTagsForCurrentPost command. But not so fast! The output contains HTML links which won’t work in a META tag. It took me awhile but I figured out how to format the output to give what we want, a plain text comma separated list. Simply add the following php code to your header.php file just below the code you just entered for the title and description.

<meta name="keywords" content="<?php if ( is_single() ) {
UTW_ShowTagsForCurrentPost("custom",array(‘pre’=>”,’default’=>’%tagdisplay%, ‘,’post’=>”));
} else {
echo " KEYWORD1, KEYWORD2, ";
}
?>" />

Replace the ‘KEYWORD1, KEYWORD2,…’ with the keywords you want to have appear for the main homepage. The UTW_ShowTagsForCurrentPost line will add the tags assigned to each post automatically. Now check the HTML source code of your page to make sure you see something like the following.

<meta name="description" content="Zaphu – Weblog written with the technophile in mind" />
<meta name="keywords" content="apple, apps, books, college, entertainment, finance, fun, images, LAMP, links, linux, mac, music, os x, reviews, sci-fi, software, tv, ubuntu" />

Congratulations!, now just sit back and wait until GOOGLE unleashes the googlebot again.


Update – CNET News has published an informative guide on META tags here.


Have something to add? Send me a message on twitter or leave a comment below.

© Copyright Zaphu 2007. All rights reserved. -- Valid XHTML

Sitemap XML Sitemap XHTML