A version of this plugin exists for WordPress 3+ only. You may want to use that unless you are running WordPress 1.5
Style-sheets are great and have completely transformed the web. WordPress is great too, and also happens to make extensive use of style-sheets, as do the many plugins and hacks that are available for it. This leads to a small problem: any plugin that requires style-sheet definitions must have them added to the main WordPress style-sheet. This is not a good thing for several reasons:
- It’s bad design to have a plugin modifying the main theme
- If you change theme, you need to make the changes all over again (if you can remember what they were)
- If you delete the theme then you have a lot of styles you don’t need any more.
I initially created a basic style-sheet plugin to solve the problem, but this soon evolved into a general purpose head
manager – head
referring to a special section of an HTML document that provides the meta-data to describe style-sheets, keywords, and an assortment of other goodies.
Reasons for using the plugin
At its most basic, the plugin allows you to add any HTML head
elements to:
- Individual posts
- Posts written by a specific users
- Posts belonging to certain categories
Why would you want to do any of that? Well, there are many reasons. The most simple is that you might want posts from different categories to appear with different styles, or maybe a post written by the administrator is in one style while posts from normal users get another.
Installation
The plugin should support the One-click format of the WP-Plugin-Mgr plugin. If installing manually then:
- Copy headspace.php to your
wp-content/plugins
directory - Activate plugin
You can find full details of installing a plugin on the plugin installation page.
Requirements:
There must be a call to wp_head ()
somewhere in your theme’s header.php
code. This is included in the default and classic themes provided with WordPress, and is likely to also occur in most themes you download. If the plugin does not work then check this first.
Using the plugin
Once the plugin is activated it is configured on a post-by-post basis by adding any of the following custom field data:
head_title |
Inserts an HTML title . Note that you are allowed one title per page, and your current theme probably provides it already. |
head_keywords |
Add meta keywords, to be picked up by search engines. Keywords are separated with commas:
|
head_description |
Add a meta description, sometimes used by search engines. |
head_style |
Add a style-sheet. The format of this is:
|
head_meta |
Add any generic meta data. The format of this is:
|
head_raw |
Add raw data. This data will simply be inserted into the head – use at your own peril! |
Wildcards
The plugin makes use of special ‘wildcards’. These are tags that are replaced with dynamic data taken from the current post:
%%nickname%%
– insert the nickname of the author%%useremail%%
– insert the email of the author%%userid%%
– insert the user ID of the author%%categoryNid%%
– insert the Nth category ID of the post (start at 1)%%categoryNdesc%%
– insert the Nth category description of the post (start at 1)%%categoryNname%%
– insert the Nth category name of the post (start at 1)%%title%%
– insert the title of the post%%date%%
– insert the date the post was created%%modifed%%
– insert the date the post was modified%%excerpt%%
– insert the post excerpt%%id%%
– insert the post’s database ID%%gid%%
– insert the relative URL to the post
Any number of wildcards can exist within a single keyword.
Examples
Add an extra style-sheet
head_style = link /wp-content/styles/example/extrastyle.css
Add a style-sheet that changes depending on who authored the post
head_style = link /wp-content/styles/users/%%nickname%%/extrastyle.css
Add keywords to the post
head_keywords = eggs,sandwiches,%%title%%
Add a description to the post
head_description = %%excerpt%%
Adding custom data
To add custom data to posts, and so get the plugin to work, you need to:
- Enable ‘Advanced Editing’
-
- Either press the ‘Advanced Editing’ button on the post
- Or enable Advanced Editing by default in the Options / Writing section of the administration screen
- Add a new custom field with a keyword being one of the above, and the value being your chosen value
The keywords should not be entered into the post itself.
Global meta data
A new feature is the ability to have a list of globally applied meta-data. That is, meta-data that is applied to every post regardless of whether it is defined in the post custom data. This would be useful to define site-wide styles and descriptions.
The global meta-data is a text file located at wp-content/plugins/headspace_global.txt
. It is a simple list of keyword and value, one per line separated with a return. All keywords and data follow the same syntax and rules as described above:
head_title This post was updated at %%modified%% head_description %%excerpt%% head_style /wp-content/styles/%%nickname%%/style.css
See also
Post-plugin research shows that Dougal Campbell wrote the plugin HeadMeta, which does a similar job to this one. The moral of the story: research before writing!
Awesome plugin mate! That beast is so powerful it’s scary!
Me again. Is there a way to get the script to print each piece of custom field data on a new line? Mine puts the title meta, desc meta & the keywords meta all on one line. I tried to do
/n
in the in the echo bit in the code but it just printed the/n
as raw header info.Version 1.1 is now available. Each item of meta-data is included on its own line. Additionally I’ve added the concept of ‘global’ meta-data, as described above.
Fantastic!!!
I’ve installed it and am ready to start using it. But, one question:
If I set up “Global meta data” in the file you explain to do, will the Meta data I put in it go to every post AND the main blog page? I’d still want my WP default title, description and keywords for the main page.
Also, if I set up the “Global Meta Data” file, will it use that for each post, and still ADD additional items from the custom fields set up in each post? For example, if I set up global keywords, and then add a keyword to a individual post, will it include the keywords from BOTH? I hope so.
P.S. Kudos to you for being a techie that can acutally write understandable documentation. 🙂
Hmmm…I’ve got it installed and activated. There is a call to wp_head in the header.php code. and it’s not working.
I’ve tried two things: 1) I entered keywords into a new custom field called head_keywords. 2) I created the global file and entered the following:
head_description %%excerpt%%
I’m not getting the excerpt to show up for any individual post — still shows what it used to show. And, I’m not getting any of the keywords added to the keyword list — still showing what it used to show.
I’m checking this by displaying the page in FireFox and then doing a View/Page Source.
Now, I wasn’t supposed to remove the existing “META NAME=”DESCRIPTION” and META NAME=”KEYWORDS” lines from the header.php file first, was I? I didn’t see that in your instructions.
Mark,
No, the meta data is only added to pages and single posts. The main blog is currently not modified.
Yes, you can have global meta data and post-specific meta data. However, it is your responsibility to make sure nothing clashes!
As for your other message…
It’s hard for me to say what is wrong. Maybe you could point me at a post on your site that has the head_keywords custom field added, and I can have a look at the output. What version of WP are you using?
I don’t quite understand your last paragraph. I have neither of those lines in any of my themes, so I’m guessing it’s specific to the theme. you use Regardless of this, the plugin just appends data to the header and it doesnt matter what is already there.
Hope this helps.
You can look at the following individual post:
http://www.googletutor.com/2005/04/18/google-sms-directions/
I did find the META tag it added at around line 40 or so. I didn’t see it all the way down there. I still have the other one up near the top. What happens when there are two of the keyword METAs, and especially when the one your plugin adds is al the way down in the style section?
Ok, I understand what you mean now. I do not know what will happen if you have multiple meta keywords. This is up to the various search engines, and I would imagine they accept them all. The HTML specification does allow multiple meta entries. The placing of the data is not important, provided it occurs within the head section.
Unfortunatley it is not possible for a plugin to replace existing meta keywords. WordPress only allows the plugin to append data. Maybe this will change in a future release but currently nothing can be done about data put in the header by the theme.
As an aside, I will look at the plugin merging keywords from the custom data and global data.
Okay.
But, I still have the problem of the Global file (headspace_glabal.txt in my plugins directory) not working. It has only one entry:
head_description %%excerpt%%
This is not inserting a HEAD DESCRIPTION anywhere.
Ugh, I uploaded the wrong version where the global data was broken. Re-download to get the lovely shiny new working version!
Thanks, that worked.
Is there anyway you could get it to insert the META lines right ater the since that is where people generally put them? right now, it goes way down below all the CSS stuff.
The data gets inserted wherever the call to
wp_meta
is located – modify your header.php so the function is before the CSS data.Aha!
It’s in my Sidebar template. That seemed like a strange place; I would have htought to put it in the Header template. But, then I read the WP docs and it saidthe following. Wouldn’t it be better in the header?
wp_meta
Should be included in the Meta section of your theme’s sidebar.php or somewhere similar.
And there goes any reputation I had for being consistent…
I meant
wp_head
, notwp_meta
! There is a big confusion in terminology in the docs.So, you need to put the call to wp_head before the CSS.
wp_meta
belongs in the sidebar as the docs rightly say.Phew
Thanks.
I searched and searched the WP docs and forum to learn more about wp_head but all I can find is that it is required in the header. I also see that wp_footer is required in the footer.
That’s WP, now I’m clear on everything LOL!
Can you take a moment to explain what these do?
They just call the plugins that modify the header and footer. With no suitable plugins they do nothing. HeadSpace attaches to the wp_head function and does its stuff wherever the wp_head call is made.
Uh Oh. I just learned something else. You said earlier that if there are two META KEYWORD tags that you thought both would be used.
Well, I’ve been researching this and I see that most people are reporting that search engines will only look at the first META tag if there are more than one of the same type.
So, unless your plugin can replace the other Meta tag that might be in there (and there has to be one for the main–not individual post–page), then the only solution I can see is to move the wp_head call up to the top of the HEAD section so it always comes before the hard-coded one.
Hi there,
I’ve installed your plugin, and used it on a number of recent posts, but I still don’t see any meta data being generated when I “view source” on either the main page, or the invividual posts. Can you help please?
I’m using head_title=%%title%%, head_description=%%excerpt% and head_keywords=”a,b,c” as required. Thanks in advance. Please email me if you can help.
Hi,
Just setting up my blog. Ugh, really want to use your plugin – it’s awesome. However, can’t get it to work.
When I try to access single post, I get this error message:
Warning: Invalid argument supplied for foreach() in /www/r/romanticcyni/htdocs/wp-content/plugins/headspace.php on line 162
I tried removing the blank line, but then I get the above message for line 322.
Can you help? Thanks in advance for any help you can give.
[…] Custom Query String ermöglicht mir die Anzahl der Artikel pro Seite festzulegen. John Godley’s Head Space und Jerome Lavigne’s Keyw […]
[…] e Special Search Options Headspace plugin I am currently testing headspace plugin. This entry was posted on Friday, Septembe […]
[…] Admincenter==>Optionen==>CQS. Damit kannst Du definieren wieviele Beiträge auf der Startseite, beim Aufruf einer Kategorie etc. angezeigt werden sollen. HeadSpace von Urbangiraffe. Dies erzeugt jenen Meta Tag: […]
I’m trying to use the headspace plugin conditionally for keywords, commments, and title tag. I want to have a default set of tags that apply to every page, and the allow those to be overridden on a page-by-page basis. How do I do this with this plug-in? All help welcome! Thanks.
Is this plugin suitable for WP 2.0?
I’m using it on WP 2.0!
But I have a problem with it:
If I use “head_raw” and insert after it my whole long Meta tags, with “(quotes) and also %%variables%% it just doesn’t show up!
Please reply!
Jamie: You are better of using another plugin I wrote called InScript – it should provide the functionality you want.
Leon: Can you post the exact text you are using? Remember that quotes inside the text must be escaped (i.e. ") otherwise it’ll cause problems parsing the string.
I now use "e; instead of ” but itdoesn’t help.
The URL to the weblog: lionstarrs Webmaster & Rätsel Weblog
The url to the headspce_global.txt – File :
Here
Hope you ca help,
thx
Ok, I understand better now. The plugin didn’t extract head_raw previously, so I’ve updated it to 1.2 – install the latest plugin. You’ll also have to change all the " to normal quotes (I thought you were trying to insert a quote inside a quoted piece of text).
Ok, I now downloaded the headspace.zip from your download link above. But it doesn’t work now, too. Maybe there’s another download link, I haven’t seen?
Thanks for the reply,
hope you can help me,
lionstarr
If you are still using the same global file then you’ll need to put head_raw on each line. The plugin only output the data on single pages, but I’ve changed it to output the global data on all pages – try version 1.3
Put head_raw on each line – didn’t help a bit.
I HAVE Version 1.3, I thibk, but I look at single Pages for the Data – where it doesn’t appear 🙁
Try downloading the plugin again – I made a slight change and using your globals file it works fine on my test blog.
Yes nw it works fine: NEARLY.
The variables are not replaced ( for egg. %%modified%% ) and I’ve one question: How do I get a line break?
Thanks for the help,
lionstarr
Hi John,
first of all, thanks for taking the time and trouble to fix all these plugins, they seem to be really valuable once put to work.
I’m trying to set up my blog and badly need to use this plugin. I have installed it, made the call within the header and tried to create keywords.
I keep on getting this message:
Warning: Invalid argument supplied for foreach() in /home/…/public_html/marketing-journal/wp-content/plugins/headspace.php on line 96
and I don’t know what to do with it…
The line 96 in headspace.php is this:
foreach ($values AS $value).
Any thoughts on what should I do and where?
Thanks a million!
Leon & Otilia: New version 1.4 will fix both problems!
That plugin is great! I will definitely give it a try this weekend! Thanks! Patric
I am using your plugin for making a custom and meta description, it works perfect! Now I would like to use the same “head_title” for another plugin: Next-Previous Page plugin (http://wordpress.org/support/topic/43071). I want/need to put the it in this line of php where it says ‘link’, here:
Is that possible?
(I tried your inscript plugin, but without php knowledge I did not even manage to have it replace the HeadSpace plugin…)
one line of php disappeared, after “here:” it said:
(hope it works now)
Downloaded for my Plugin Collection 🙂 Thanks, great Job!!!
Any chance of getting this plugin to work with WP 2.1?
It’s the only plugin I’ve found that’s simple to use and will create a tag.
The errors are:
Warning: implode() [function.implode]: Bad arguments. in C:\axampp\xampp\htdocs\projects\wordpress205\wp-content\plugins\headspace.php on line 368
Warning: Invalid argument supplied for foreach() in C:\axampp\xampp\htdocs\projects\wordpress205\wp-content\plugins\headspace.php on line 412
Warning: Invalid argument supplied for foreach() in C:\axampp\xampp\htdocs\projects\wordpress205\wp-content\plugins\headspace.php on line 418
Many thanks,
Richard
Sorry, that should have read title tag but it was stripped.
Also the file path looks like wp 2.05 but is really 2.1
Reeally nice plugin, thanks a lot!
One thing, that doesnt work:
%ÊtegoryNid%%
I can put %Êtegory1id%% or %Êtegory2id%% or .. or …
But nothing happens 🙁
Greetings from germany!
Richard, there’s a version for WordPress 2 at http://urbangiraffe.com/plugins/headspace2
Really great, also for Search Engine Optimizer like me 🙂 thanks a lot.
On posts I’m trying to stop the tags from showing up in the meta keywords, but no matter what I put in the Tags/keywords section of the Posts & Pages settings the tags keep showing.
David, currently there is no option to disable tags from appearing in meta keywords. Can I ask why you want to do this?
If I use 50 tags in a post then having those 50 words/phrases in the head section just makes for clutter and is almost 100% useless in terms of seo. I just don’t like clutter and fluff. It might be nice to be able to limit the number of words that appear in the meta keywords, or just to not use them at all. Really what I’d like to do is just use the post title in the keywords.
Right, that’s understandable. I’ve created a feature request for this, and it will probably get folded into the plugin in the future.
Any expectations for getting this to work with WordPress 2.5? The auto-tagging seems to be busted by the new upgrade.
Kevin, HeadSpace is no longer supported. HeadSpace2 (which works in WP 2.0-2.5) is over on the HeadSpace2 plugin page.
How do I remove the “»” or » from the titles output by HeadSpace?
Matt, you need to modify header.php in your theme.
Hi John, thanks for a great plugin.
I took the HeadSpace2 zip file, unzipped it, and put it in my WP plugins directory. I activated it in WP and then went to Settings -> Plugins. I am looking under “Page Settings” and click around Global Settings, Home Page, etc. but the clicking doesn’t take me anywhere.
Then, I click on Modules, Options, and Import and get a 404. I doublechecked that I am extracting the files correctly, etc. Have you heard of this happening before?
Thanks.
Either you havent uploaded the files in the correct directory structure or maybe another plugin is interfering.
Hi John,
do you have an example of site where you use the headspace plugin?
Yes, this site uses HeadSpace
Is this plugin available for WordPress 3+ . If not is there an alternative. Ive not been able to find one.
It is available for WP 3+