Mark Pilgrim was in the #wordpress IRC channel earlier, asking if there was some way to add <link> and <meta> tags to the <head> section of a page for specific posts. It seems he wants to control how various search engines and other bots index individual posts. I replied that he could do this using the custom fields feature.
A short while later, I had written my first plugin for WordPress: HeadMeta: .ZIP, .tar.gz, .phps, .txt.
To use this plugin, you add key/value pairs in the Advanced Editing interface. In particular, you’ll want to add keys named “head_link” and “head_meta”. The value will be plugged into the generated <link> or <meta> tag. For example, if you added the following keys and values:
| Key | Value |
|---|---|
| head_link | rel=”seealso” href=”http://example.com/movies/” |
| head_meta | name=”keywords” content=”entertainment,movies” |
This would generate two tags in the <head> of the page, when someone visited the permalink for the post:
<link rel="seealso" href="http://example.com/movies/" />
<meta name="keywords" content="entertainment,movies" />
This will be useful for any situation where you want special <link> or <meta> tags generated for specific posts.
UPDATE 2005/07/14: I’ve updated the plugin to version 1.1, which adds a new feature: if you have a key named “keyword” or “keywords”, it will automatically generate a standard “keywords” meta tag. For example, if you have the following custom field:
| Key | Value |
|---|---|
| keyword | pets, dogs, canines, training |
The result would be:
<meta name='keywords' content='pets, dogs, canines, training' />
UPDATE 2005/10/15: I updated with a bugfix. The new version is 1.2.
UPDATE 2007/02/05: Version 1.3 is the newest version, which is now WordPress 2.1 compatible (it should still work with older versions, as well). Thanks to Gerald for pointing out the problem!
My first WordPress plugin: HeadMetaRelated posts:
- HeadMeta Update
" Prompted by some recent comments, I have made a minor update to my HeadMeta Plugin. There are now links to the color-coded PHP source,..." - HeadMeta 1.4
"Due to changes in the postmeta API, my HeadMeta plugin had a compatibility problem with some recent versions of WordPress. The problem appeared when there..." - XCache Object Cache Plugin for WordPress 2.5+
" Download: xcache-plugin.zip Version: 0.7d Updated: August 29, 2008 Size: 1.94 KB Powered by Drain Hole This is another one of those articles that will..." - Text Filter Suite Plugin for WordPress
"Since Talk Like a Pirate Day is only three weeks away, I spent some time this weekend revamping my old Fun Filters hack. The result..." - Plugin: SpamForceField
" SpamForceField is my newest anti-spam plugin for WordPress. This one does a couple of interesting things: All connections via pinappleproxy are denied. Every connection’s..."














77 Comments
I updated your code to have the ability to use the key “description” and the value to be whatever you want the description to be. Contact me if you want it.
Cheers for making this plugin! I find it very useful!
-John
I have problems using it with wp 2.0.7 – it inserts the values correctly, but when generating the page / post for viewing it seems not to pull out the values, the generated page does just not contain any keywords meta tag..
any ideas?
ovidiu: are you using a custom theme? If so, make sure that its header calls the
wp_headaction. See above for more details.well, header.php does include a call to wp_head…. I guess another plugin is interfering. Your plugin was the first I used for this but as I had problems, I tested a couple of others and to be honest 3 other s didn’t work too, so I guess its another plugin I am using that interferes…
I will just test your plugin again in a new blog, when needs arise, and test it first, before activating other plugins. fyi the theme I am using is the apart theme from gluedideas.
Thanks, Dougal – I like that plug-in a lot!
I noticed that it does NOT work any more in WP 2.1 – unless you modify lines 46 and 47 of headmeta.php. The modfied lines are:
[46] $metavals = get_post_meta($id, ‘head_meta’, false); // $post_meta_cache[$id]['head_meta'];
[47] $linkvals = get_post_meta($id, ‘head_link’, false); // $post_meta_cache[$id]['head_link'];
I have kept the original code as a comment, just in case.
This is due to the fact that “as of WordPress 2.1, $post_meta_cache isn’t populated anymore.”, see http://codex.wordpress.org/Using_Custom_Fields for detailled information.
Now WordPress 2.1 compatible.
I noticed that if you already have meta description in your header.php file and you use this then both descriptions show up. Does that cause any problems with search engines? Which description will they prioritize?
Thanks – great plugin!
i downloaded the vital plugin + installed it. But I get always the error : “parse error, unexpected T_RETURN in…â€
It doesn work!!!
((
Can you be a little more vague, please?
thx for this very very useful plugin!
Your Plugin Headmeta throws a fatal error with my WP 2.3.1 installation. Is there any way to track the error, since you say that it is compatible with that version?
Matthias
Does anyone know of any issues with this plugin and WP version 2.0.7?
I have found that this plugin still works after I updated my blog to 2.51 which is great news. I have found that this plugin does clash with some themes I use so it’s always worth checking this out. Apart from that this plugin totally rocks great job.
You can now add meta data like keywords and description using Custom Fields in the latest version of wordpress, and the get_post_meta function. Still, you’d have to be able to work out a bit of PHP to do it, so perhaps a plugin is better!
There was some PHP code at the link on my previous post, but the link has been truncated for some reason… Anyway, if anyone wants to see the PHP that I hadn’t even mentioned was there, click my name and look for it in the wordpress category …
Nice plugin and easy to use
Check out Malcolm’s page in comment 66 and you are given the simple solution to use meta keywords and meta descriptions for your posts without using any plugins.
Awesome resource for tricks, glad I found this blog and there are hundreds of pages of info, awesome. The web is really a great place.
I am going to plug- in. I think this would help me in more ways than one. My brother has already used it and he says that it rocks! Kudos!
Heads up, tried it out and it works like a charm, thanks again.
Hi! This plugin doesn’t seem to work in wordpress 2.8.3. I’ve installed and activated it, but anything is shown in the panel editor.
There’s not a settings page for the plugin. You just set Custom Fields on your post, and it will automatically add the appropriate headers when you publish it.
Oh! I understand now. I use the “Custom Fields” bought by default in the post editor panel of WP, setting datas for “head_link” and “head_meta”. Right?. Thanks you, it’s so useful for me. Montxo.
excellent post. but i dont think search engines, and google in particular, view keywords as much at all.
This script not work with WordPress 2.0
27 Trackbacks