HeadSpace Plugin

Apr 14, 2005 | Tags: , , , | Written by John
Version 3.6.2 of this plugin exists for WordPress 2+ only. You may want to use that unless you are running WordPress 1.5

download

Download: headspace.zip
Version: 1.4
Updated: September 18, 2007
Size: 2 KB

Support This Plugin!

While this software is being provided free to use, it takes considerable time to develop and support. If you do find it particularly useful or want to request a feature then consider donating money as an incentive for me to carry on developing it.

Thanks!

I have other plugins too!

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:

  1. Copy headspace.php to your wp-content/plugins directory
  2. 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:

example,eggs,cheese

head_description Add a meta description, sometimes used by search engines.
head_style Add a style-sheet. The format of this is:
  • import type url - where type is an import type (screen, TV, projector etc)
  • link url
head_meta Add any generic meta data. The format of this is:

name="something" content="content" equiv="httpequiv"

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:

  1. 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
  2. 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!

Share This

Comments (page 1 of 6)

  1. John (author) :

    Apr 19, 2005 11:20 pm

    Ugh, I uploaded the wrong version where the global data was broken. Re-download to get the lovely shiny new working version!

  2. Mark Fleming :

    Apr 19, 2005 5:54 am

    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.

  3. John (author) :

    Apr 18, 2005 11:51 pm

    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.

  4. Mark Fleming :

    Apr 18, 2005 11:01 pm

    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?

  5. John (author) :

    Apr 18, 2005 1:42 pm

    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.

  6. Mark Fleming :

    Apr 18, 2005 1:10 pm

    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.

  7. Mark Fleming :

    Apr 18, 2005 12:30 pm

    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. :)

  8. John (author) :

    Apr 18, 2005 4:11 am

    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.

  9. Lars Jansen :

    Apr 18, 2005 2:37 am

    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.

  10. Lars Jansen :

    Apr 18, 2005 2:12 am

    Awesome plugin mate! That beast is so powerful it's scary!

Leave a comment


XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Home | Software | Terms & Conditions | Sitemap | John Godley © 2008
Close
E-mail It