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!
Pingback: ABQ Group Weblog
Pingback: Blogging Pro - Blog News, Tools and Hacks » WordPress Plugin: HeadMeta
Pingback: Weblog Tools Collection » geek ramblings >> My first WordPress plugin: HeadMeta
Pingback: Blogging Pro - Blog News, Tools and Hacks
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.
Pingback: Taking Your Camera on the Road » Really Rocking with WordPress
Pingback: Taking Your Camera on the Road » Really Rocking with WordPress
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.
Pingback: geek ramblings » HeadMeta Update
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!
Pingback: Jens!Picek :: News-Blog » Blog Archive » Unser News-Blog und die Plugins
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
Pingback: SonicChicken weblog » Blog Archive » New website for my wife’s business
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.
Pingback: Blogger Tipps und Hilfe » Archiv » Metatags in Wordpress einbauen
Pingback: SonicChicken weblog » Blog Archive » CJD on Google Earth
Pingback: a.css, esbudellant està ndards » Metadades personalitzades pel WordPress
Pingback: Combining Bunny Technorati Tags and Head Meta Plugin | Webmaster Resources Information
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:
Pingback: The Online Developer
Pingback: Wordpress meta-tags - Platinax Business Forums
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…â€
Pingback: Update for HeadMeta plugin for WordPress 2.1 - Recommended Web Tools
Pingback: Brandon Buttars » WordPress Meta Tags Plugin
It doesn work!!!
((
Pingback: Wordpress META Plugin List | ngadutrafik2007
Can you be a little more vague, please?
Pingback: UmatBlog » WordPress very exPRESSive
Pingback: Update for HeadMeta plugin for WordPress 2.1 | READER: Webmaster
Pingback: WP Plugins DB » Plugin Details » HeadMeta
thx for this very very useful plugin!
Pingback: WhyDoWork.com Work at Home Blog » Top 5 Wordpress Plugins for Bringing Traffic
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?
Pingback: HeadMeta_Wordpress plugin
Pingback: geek ramblings » WordPress 2.5 Beta
Pingback: Weblog Tools Collection » Blog Archive » New AB Meta Markup Tools for WordPress
Pingback: ThinkLite » Wine, Film and Books: Adaptive Blue Offers Open Format to Make the Web Smarter
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.
Pingback: Wine, Film and Books: Adaptive Blue Offers Open Format to Make the Web Smarter « Mayank’s Weblog
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