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!












Heads up, tried it out and it works like a charm, thanks again.
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!
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.
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.
Nice plugin and easy to use
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 …
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!
[...] want to mark up particular pages or post pages with AB Meta can do so using Dougal Campbell’s HeadMeta WordPress plugin. Some post-level meta data editing is possible with Typepad but Blogger users are out of luck. [...]
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.
[...] want to mark up particular pages or post pages with AB Meta can do so using Dougal Campbell’s HeadMeta WordPress plugin. Some post-level meta data editing is possible with Typepad but Blogger users are out of luck. [...]
[...] that can be used by search engines to correctly categorize and annotate content. Dougal’s HeadMeta WordPress plugin can be used to insert AB Meta into your posts. The Wired article and the Adaptive Blue blog post [...]
[...] since I know lots of people will ask, I checked my plugins, and most of them (HeadMeta, Text Filter Suite, and Easy Gravatars), work just fine. The one that doesn’t work is Theme [...]
[...] Plugin Homepage [...]
Does anyone know of any issues with this plugin and WP version 2.0.7?
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
[...] used to be, they can still influence the results you get from search engines. Using a tool such as HeadMeta which allows you to give Meta tags for each post you have on your blog means that you can increase [...]
thx for this very very useful plugin!
[...] Visit [...]
[...] WordPress to generate description meta tags and are using WordPress 2.1 you will need to update to version 1.3 of the plugin. Previous versions do not work. Simply download the new plugin file. [...]
[...] HeadMeta [...]
Can you be a little more vague, please?
[...] (http://dougal.gunters.org/blog/2004/06/17/my-first-wordpress-plugin-headmeta) Provides per-post custom <link> and <meta> [...]
It doesn work!!!
((
[...] of all I just need to give credit to Dougal Campbell because I more or less just took what he did and made it a little bit easier and more Search Engine [...]
[...] WordPress to generate description meta tags and are using WordPress 2.1 you will need to update to version 1.3 of the plugin. Previous version do not work. Simply download the new plugin file. [...]
i downloaded the vital plugin + installed it. But I get always the error : “parse error, unexpected T_RETURN in…â€
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!
Now WordPress 2.1 compatible.
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.
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.
ovidiu: are you using a custom theme? If so, make sure that its header calls the
wp_headaction. See above for more details.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?
Cheers for making this plugin! I find it very useful!
-John
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.
[...] <meta name="description" content="<?php the_title(); ?> at <?php bloginfo(’name’); ?> <?php the_excerpt(); ?>" /> <meta name="keywords" content="<?php the_title(); ?> at <?php bloginfo(’name’); ?>. " /> That at least generates a meta-description, which to me is the more important of the 2 tags meta description and meta keywords – especially for avoiding Google’s duplicate content filters. However, there are meta-tag generators out there for Wordpress. I’m currently playing around with the Xfish one, as I can control tags per page – quite important in a client install of a CMS – but there’s quite a few to choose from: Add Meta Tags – Adds the post’s categories and the post’s excerpt as keywords and description meta tags respectively, while viewing single posts. AutoMeta – Automatically generates and publishes Technorati Tags and Meta Keywords based on the content of your post (it utilises the MySQL full text index for word scoring). Once generated, tags can be hand-finished to ensure pertinence. Category Tagging – Provides a tag cloud and related posts. When using this plugin, you can use the WordPress’ categories as tags — no additional tagging plugin is needed. Creative Commons Configurator – Lets you set a CC license for your blog and set options to include licensing info in the blog header (RDF metadata), after the post’s body (HTML) and in the syndicated content (Atom, RSS2, RDF) through the CC RSS module. All this is done from a configuration page in the Administration Panel. Custom Field GUI – Enables the automated creation of form element user interface for entering Post’ custom field(s). FOAF Header – Add a FOAF link to your page’s header. FOAF Output – Personal profile page with friends (XFN) and interests, FOAF RDF/XML profile including trust statements, and extended RSS (1.0) output. Get Custom Field Values – Easily retrieve and control the display of any custom field values/meta data for posts. Head META Description – Automatically add a meta description tag to posts, Pages, categories and elsewhere on your blog. Fully customizable. HeadMeta – Provides per-post custom <link> and <meta> tags. Jerome’s Keywords – Associate keywords with your posts. Jerome’s Keywords: Related Posts – This Plugin uses Jerome’s Keywords and presents related posts according to the tags (keywords) of the current post. Jerome’s Keywords Manager – Manage keywords entered via Jerome’s Keywords. KeyCloud Widgets – Sidebar widgets to display your Jerome’s Keywords in various forms, including the venerable tag cloud. Keywords – Append keywords into Meta tags from ‘keywords’ custom field. META Relationship Links – Adds START, FIRST and LAST rel(ationship) link tags to your blog, as well as PREV(ious) and NEXT for individual posts. myStatus – Creates a subpanel of the Dashboard that allows you to create a number of fields to specify your current status and insert it into your templates. RSD 1.0 – Adds RSD support to WordPress. Tags in the Head – Tags in the Head attempts to make your website both more machine and human readable by using the ‘Tags’ you specify (from Jerome’s Keywords or Ultimate Tag Warrior) as META keywords in a page’s header. It also allows you to customize the meta description’s for various parts of your site. Tags in the Head combines good SEO with commonsense organisation using tags. Userextra – Extends user profiles to include admin-defined attributes, and provides for category access controls with per-user granularity. Usermeta – Adds API for WordPress 1.5 so that arbitrary meta data can be associated to users. Xfish_meta – Allows the inclusion of meta tags like keywords and description __________________ Search Engine Optimisation consultant Need search engine traffic? I can help: Britecorp SEO services [...]
Wordpress plugins: meta-tags…
Wordpress is a great piece of software for development purposes, and I especially like to set up customised versions as a CMS.
Wordpress has many great strengths, but a particular weakness is that i……
It’s working fine here, under WordPress 2.0.4.
If you view source on this page, you can find the following three tags generated by the plugin:
This script not work with WordPress 2.0
i have problem wih my blog under http://www.dsl-presse.de, can somebody help me or say whow i can deactivate that the startsite (homepage) are so long, is t better to have a short homepage (first site)?
Whis metatags i dont understand whow the plugin is to install and if it possible to have diverent tags for all sites, plese mail me.
Whoops! Forgot the code tags-
It is my understanding that there is no problem with having (2) meta tags for keywords (or description) as long there is no duplicate content. You can keep a more general, permanent keyword meta tag in your header, then use this plug-in to further refine the tagging. The search engines will combine the content as long as the length limit is not exceeded. You can repeat a ‘word’ but not a ‘keyword’.
Example –
stays in the header. Then, use the HeadMeta plugin to generate a second tag
. Both will appear in header section of the page source.Great plug-in!
Thanks for plugin! Dougal
It is my understanding that there is no problem with having (2) meta tags for keywords (or description) as long there is no duplicate content. You can keep a more general, permanent keyword meta tag in your header, then use this plug-in to further refine the tagging. The search engines will combine the content as long as the length limit is not exceeded. You can repeat a ‘word’ but not a ‘keyword’.
Example – stays in the header. Then, use the HeadMeta plugin to generate a second tag – . Both will appear in header section of the page source.
Robert
Hi: I am not getting any meta data and having written some simple de-bugging lines, it looks as if $metavals is not being populated. Running on WP2.0.2 … I’m not a PHP developer, but I can follow what the code is doing and making small tweaks. Also, where in a normal instalation, would I find the error logs people are referring to please?
It’s all working fine now. I think it may have had something to do with the way I was viewing the page having added the values.
Referring to my previous comment, part of which didn’t show up I’ll try again.
The header.php file has the line: <?php wp_head(); ?>
Problem: meta tags not showing in of page.
I have previously successfully installed the Headmeta plugin in WP version 2.0.2, but I’m not having any success with WP version 2.0.3
I’m using the same theme (Gila)
header.php has the line in it.
I’m using the key head_meta and values name=”keywords” content=”CMS” and name=”description” content=”some description”
Does anyone know of any issues with this plugin and WP version 2.0.3?
I must have something set wrong. The only thing that’s showing up on my Google ads are concerning blogs, and that’s not what it used to show before I just had to recover everything. Any ideas on what I might have missed?
There’s not a line like that in the HeadMeta plugin. Double check the error message to see what file it’s coming from.
Parse error: parse error, unexpected T_RETURN
that’s the error i get for line 21
line 21 reads:
$j == FALSE? return substr($string, $i++);
[...] You can combine Bunny Technorati Tags Plugin and Head Meta Plugin for your Wordpress blogging software. [...]