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: HeadMetaNo related posts.















76 Comments
This is nice! Now we can have more high-ranking wp-powered sites in google. This should help provide exposure for those deserving.
Uhmmm, if I download http://dougal.gunters.org/headmeta.phps then bad bad things happen. Perhaps you could make a plain link to the code, or are you just showing off?
Thanks,
-danny
Ah, that’s the PHP source auto-formatting. You could just cut-n-paste the text from your browser. But to make things easier, here’s a plaintext version:
http://dougal.gunters.org/headmeta.txt
Message from WordPress Plugin Manager: “Fatal Error: Could not find plugin file in zip archive. Please contact developer and tell him to insure that his plugin is correctly named (should be: ‘headmeta.php’).”
I just spent the last 30 minutes making a plugin that does exactly the same thing — DOH! I knew I should have searched first.
Oh well, yours is smaller, so it looks like I just wasted my time
I think I’m missing something – I’ve installed the plugin with no problems, and then added a custom head_meta, but nothing extra at all appears in my <head> – no errors or anything, just…nothing.
Ah – you need the wp_head line in your head for it to work.
I just moved my webhosting yesterday and I’m looking for better ways of getting better results in the search engines. Your plug in looks great. I’m going to try it out, but I noticed you said in post 10 that I need the wp_head line in my head to make it work. Where does that actually go?
I’m also wondering if I also can put metatags in any page on my site for better rankings. Just go to http://www.thecheapestlink.com to see my daily deals site that I’m trying to develop all over again now that I’ve moved, but I like version 1.5!
Thanks for any help you or anyone else can give,
Barry
Barry,
If you are using the default WordPress theme, it already has the wp_head() call in there for you (look at wp-content/themes/default/header.php, near the end). If you are creating your own theme (or using a third-party theme), just make sure that within the <head> section of the HTML, you have a line that says:
<?php wp_head(); ?>This is what tells WordPress where to handle calls associated with the wp_head hook.
Tries your plugin in my 1.5 version. But can’t see that it work. I uploaded the file and activated it, but no extra fields are shown. Do you have any idea why?
Thanks in advance
Yeah I was wondering the same thing. Does this plugin work with 1.5?
If you are using a custom theme, make sure that it is hooking into the wp_head API action. In the standard themes, this is handled in the header.php file, by including this code inside the html
<head>section:<?php wp_head(); ?>Alternately, some themes might do it like this:
<?php do_action('wp_head'); ?>If one of those code snippets doesn’t appear in your theme code, none of your plugins will be able to use the wp_head API call properly.
Hey there. I am having a problem with the plugin whenever it gets activated…it’s the same problem that happens with Xfish meta actually. I get this line of errors at the top of my page http://www.eliboat.com :Warning: Cannot modify header information – headers already sent by (output started at /usr/home/eliboat/public_html/wp-content/plugins/headmeta.php:1) in /usr/home/eliboat/public_html/wp-admin/admin.php on line 6
Warning: Cannot modify header information – headers already sent by (output started at /usr/home/eliboat/public_html/wp-content/plugins/headmeta.php:1) in /usr/home/eliboat/public_html/wp-admin/admin.php on line 7
Warning: Cannot modify header information – headers already sent by (output started at /usr/home/eliboat/public_html/wp-content/plugins/headmeta.php:1) in /usr/home/eliboat/public_html/wp-admin/admin.php on line 8
Warning: Cannot modify header information – headers already sent by (output started at /usr/home/eliboat/public_html/wp-content/plugins/headmeta.php:1) in /usr/home/eliboat/public_html/wp-admin/admin.php on line 9
Any idea what is going on here? ANy help is much appreciated. Thanks,
Eli
90% of the time, errors of that type mean that you have some extraneous whitespace at the beginning or end of the plugin file. Make sure you don’t have any blank lines (or even spaces) before the opening “
<?php” or after the ending “?>“.Nice idea
Thx for the plugin
I really appreciate the great plugins available for WP users & I’m sure that this is a good one as well. But PLEASE, plugin authors, don’t write your instructions for people with your level of technical knowledge. Write them for the average WP user (like me) who may have some technical knowledge, but not as much as you.
What I’m saying is that above there may be instructions on what to do to install this plugin but I couldn’t find them. The stuff that looks like it might be intructions doesn’t tell you what to do with the plugin code. Where do you install it?
A little basic help would be much appreciated.
After much trial & error I think I’ve got it working. A few suggestions: Dougal, you have introduced the white space in the file you link. There was space at the beginning & end of the file. ONce I removed that it installed.
Also, it would be much easier if you offered the file as a notepad doc or zip so that we wouldn’t have to cut & paste text, create a file name, etc. I tried installing the file as .txt & then as .phps (the 2 suffixes you used above). Nothing worked until I used the .php suffix. This may seem elementary to some of you but it wasn’t to me.
Dude, you rock! I tried a few plugins that did the meta tags but yours was the best and easiest to integrate with the other plugins I was using. I saved the formatting for keywords and description and was opening a notepad file to copy, paste and edit every single post. It got tiring so I quit a few days ago.
This NEW adjustment is the bomb! Thank you, thank you, thank you — a million blessings upon you.
Seems to work great! Very useful. Not that I’m not content with my two regular readers.
I am a bit in the dark still about meta tags. I haven’t added any to the main page of my weblog, such as a decription and some keywords. How will that play with this and the ? tag? I guess that’s probably a question for the WP support forum.
Thank you for this plugin! Very useful!
This works well on posts, but doesn’t appear to work on the pages feature of Wordpress. Is this the case? If so is there anyway it can be used?
Dougal: I guess I’m confused by a few things.
I’m assuming that by the phrase above you mean to say that I can create a new custom field (which is WP’s term for what you’re talking about–I think) called “keyword.” You use the term “key” & I just wanted to make sure we were talking about the same thing.
But how would this be diff. than the old method by which you invoked a custom field call meta_tag? Or are you saying that you can have a series of custom fields for posts which share the same general subject & whose keywords might be similar?
I hope you’ll help clear this cloud over my head…
Mike: I’ll release an update soon that works on pages.
Richard: Sorry about the confusing terminology. Yes, I’m talking about the post custom fields, which have a “key” and an associated “value” for the key. The using the word “keywords” as the key is a shortcut for a “keywords” meta tag. The following pairs of keys and values would be equivalent:
KEY: head_meta
VALUE: name=”keywords” content=”entertainment,movies”
KEY: keywords
VALUE: entertainment,movies
These will both generate the exact same <meta> tag in the header. It’s just that the second form is easier to use.
I am testing the instalation, I loved this WordPress.
It seens to be easy to manage, I hope so.
I am looking for plugin to have but button of XML, Atom, Yahoo, etc. Exist plugin?
Thanks.
I still get the same error message.”headers already sent by (output
started at …catalog/includes/application_top.php:509)”
hi dougal, i’m try this plugin on my trial site and it’s a miracle
i’m looking for one to do that for a long time
you make an excellent plugin. it’s easy to install and run (i’m don’t know nothing about php)
thanks!
i’l like make only a question. this plugin works perfect on posts but doesn’t works on the pages, why? it’s there anything can i do to resolve that?
thanks again and sorry for my bad english (i’m try writte, but i don’t know your language well)
Just downoaded this vital plugin and installed it. But I get the error which says: “parse error, unexpected T_RETURN in…”
Any solution would be appreciated.
Thanks in advance
Warning: array_merge() [function.array-merge]: Argument #1 is not an array in XX/wp-content/plugins/headmeta.php on line 52
I’m using PHP5, and that’s the warning that appears into one page.
Any solutions?
I’ve changed this
$keywords = array_merge($post_meta_cache[$id]['keyword'],$post_meta_cache[$id]['keywords']);
for
$keywords = array_merge((array)$post_meta_cache[$id]['keyword'],$post_meta_cache[$id]['keywords']);
and the warning has disappeared
I tried installing the headmeta plugin, and like Shekharpoorna earlier in the comments (Sep 29), I received the following error when I tried to activate it:
“Parse error: parse error, unexpected T_RETURN in /path-to-my-wordpress/plugins/headmeta.php on line 39″
Line 39 reads:
if (!(is_single() || is_page()) return;
If I can get the basic plugin to work, my next order of business will be to attempt tweaking it to automatically do with a ‘description’ tag what you already have it doing for ‘keyword’ or ‘keywords’. Thanks for the plug-in.
Well, I’ll be. Thanks for posting that line, I noticed what the problem was. It was missing a paren at the end. It should read:
if ( !(is_single() || is_page() ) ) return;I added extra spacing for better readability. Notice that there are three closing parens at the end, not two.
Sorry about the mistake. I’ve updated the downloadable versions.
good stuff, now i will raise my botd-isms
If I use this plugin I can do keywords, however, it it possible to also use this
plugin to generate –
Description, Abstract, Author, Robots, and Distribution
Meta Tags?
Thanks,
Paul
thanx for the plugin
Greetings
Quick Question.
I just installed this, however when I view the sorce of my page, I don’t see the keywords.Did I do something wrong?
Thanks
Lana, make sure that your blog theme is calling the wp_head action. There’s a previous comment with more details.
Hello -I am getting the same error message as “kike”:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in \\nas-001\winspace002\10-21stcenturygirl.net\www\wp-content\plugins\headmeta.php on line 53
I applied his fix but still no luck
still wondering if anyone knows how to get this plugin working when you get this warning:
Warning: array_merge() [function.array-merge]: Argument #2 is not an array in \\nas-001\winspace002\10-21stcenturygirl.net\www\wp-content\plugins\headmeta.php on line 53
tried -sugested “fix” -no luck.
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++);
There’s not a line like that in the HeadMeta plugin. Double check the error message to see what file it’s coming from.
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?
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?
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(); ?>
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.
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?
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
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!
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.
This script not work with WordPress 2.0
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:
27 Trackbacks
[...] a slvShowNewIndicator(1087503277); Filed under: WordPress Plugins|Google it! This plugin for WordPress gives the author an option to provide unique [...]
[...] Meta Filed under: Cool Scripts WordPress Hack LinkyLoo — Mark @ 1:17 pm geek ramblings >> My first WordPress plugin: HeadMeta: To control ho [...]
d like it to. I want dates up when viewing archives – basically mirroring the new fancy permalinks added image upload capability TODO: this and this to kill comment spam (or other methods) PHPMyAdmin Comment Preview meta/tags higher ranking in google? (prob not)
WordPress Plugin: HeadMeta
This plugin for WordPress gives the author an option to provide unique <link> and <meta> tags to individual posts. Specifically you can enter keywords and the seealso tags.
[...] RL Charles Gagalac – Protects against a comment flood based on the commenter’s URL
HeadMeta – v1.0 Dougal Campbell – Add [...]
[...] Charles Gagalac – Protects against a comment flood based on the commenter’s URL HeadMeta – v1.0 Dougal Campbell – A [...]
[...] 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, a plaintext version, a .ZIP file, and a .tar.gz tarball. [...]
[...] Desweiteren haben wir das Plugin Headmeta eingebaut. Im Adminteil wollten wir auch gleich die Funktion haben, die Keys direkt einzugeben. Gesagt, getan… Leider mit etwas merkwürdigen Eigenschaften. Beim Klick auf “Beitrag/Seite schreiben” haben wir im Moment je 14x das Benutzer definierte Feld zur Eingabe der Keys. Ich nehme an das sich das pro publizierten Beitrag um eins erhöht. Mal Dirk fragen, was man da machen kann. [...]
[...] HeadMeta, which I’ll be using for per-post geotags for things like quilt shows, mail-order and retail stores, as well as other posts/Pages that can reasonably be geotagged. I’ve already made sure that the Dixie Belle theme is activating the WP header hooks — Jennifer seems like the type that would have done the Right Thing, and she did! [...]
[...] Man ging das einfach Das Plugin speziell für Wordpress gemacht hier downloaden. Zip file downloaden, entpacken und per Ftp in den Ordner Wp Content – Plugins hochladen. Dann im Admin Bereich den Plugin aktivieren und fertig. [...]
[...] I still haven’t gotten around to setting up HeadMeta for geotagging posts, but CJD’s article(s) may be the kick in the butt that I seem to require to get this done. [link] [...]
[...] El plugin HeadMeta permet afegir de manera simple tants elements link o meta com desitjem per un post determinat. [...]
[...] You can combine Bunny Technorati Tags Plugin and Head Meta Plugin for your Wordpress blogging software. [...]
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……
[...] <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 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. [...]
[...] 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 [...]
[...] (http://dougal.gunters.org/blog/2004/06/17/my-first-wordpress-plugin-headmeta) Provides per-post custom <link> and <meta> [...]
[...] HeadMeta [...]
[...] 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. [...]
[...] Visit [...]
[...] 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 [...]
[...] Plugin Homepage [...]
[...] 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 [...]
[...] 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 [...]
[...] 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. [...]
[...] 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. [...]