WordPress Plugin: Head Meta – Add Anything to the <head> of a Post

Latest version: 0.2 – Released 21 March 2007

Description

Ever wanted to add things such as JavaScript or meta data to the <head> of a page when you’re writing a post? It usually means editing the header.php file in your blog’s template, which is time-consuming and especially complex if you only want to add it to certain pages or posts. This is where the Head Meta plugin comes in. It allows you to simply type your meta data or your JavaScript into a custom field and have it show up inside the <head> on your post or your page.

Example

On the page for my Firefox Twitter Updater I needed to insert a <link> into the head, but have it only inserted when viewing that blog entry on its own. I typed the whole <link> element into a custom field named “head-meta” and while the plugin is active the <link> shows up in the document’s <head> without having to alter anything in the template. See the screen shot below:

Example of usage of the Head Meta plugin for WordPress

Installation

This plugin is only recommended for people who are comfortable writing HTML by hand and who know what meta data is. If you don’t know why you’d need this plugin, then you don’t need it. For those who do, download the plugin using the link at the bottom of this page, unzip it and drop the head-meta folder straight into your wp-content/plugins directory and activate the plugin from WordPress’ Plugin panel.

Your WordPress theme must have the wp_head() function inside the head for this plugin to work. The default themes bundled with WordPress have this, and many themes you can download do too, but if this plugin doesn’t work for you please ensure this function is in the head of your theme.

Usage

Using this plugin is easy. Simply type the meta data which is to go into the <head> of your post or page into a new custom field and name the key “head-meta” (without the quotes). Take another look at the screen shot above if you’re not entirely sure.

Download

ZIP file from johnblackbourn.com

More Details

The meta data will only show up in the <head> of your document when viewing the post or page on its own (ie. at the post’s permalink). It will not show up, for example, on the front page of your blog even when the post concerned is visible on the front page. This is because my particular needs were that I only wanted the meta data to show up when viewing the post on its own.

Any comments, questions, queries, suggestions, complaints, etc, please leave a comment below!

44 replies on “WordPress Plugin: Head Meta – Add Anything to the <head> of a Post”

  1. Ok, now I’m confused. There is already a well known plugin by Dougal Campbell named “HeadMeta” which I believe currently is at version 1.3.

    I think the similarities in names is more than a little confusing. It seems like yours is a bit different in that it allows the input of JavaScript and not just meta keyword tags, but it is still confusingly close.

  2. Storm, I hadn’t come across the previous plugin named HeadMeta. You’re right, the names are very similar, I may change mine as obviously my plugin came after!

    Hackemster, what version of WordPress are you running? Did this happen before or after you tried inputting some data in the custom fields? What other plugins are you running?

  3. It fails for me also… Blank screen when activating in 2.0.4 and 2.1 (fresh install)

  4. Awesome !
    Like you, I had to use custom JS and CSS on several posts.

    I’ve installed this, it works great. Thanks !

  5. Shaun, thanks for trying the plugin. That’s a side effect of the fact that I knocked up the plugin in 10 minutes :-)

    If you want to add more than one meta tag you’ll just have to add them all into the same custom field (“head-meta”) one after the other.

  6. I have installed this plugin and it seems to be exactly what i want for adding keywords and descriptions to the head of my posts. The only problem i have is it only seems to let me put one set of meta information in for each post, for example i created meta description information for one of my posts and that worked perfectly, i then went to add the meta keywords but they don’t show up in the code for some reason?

    Tried it on a few different posts with the same results.

    Any ideas why this might be happening ?

    Thank You

  7. Hi John,

    Thanks for the reply, i figured it out by playing around with it. Working great now. Thanks

    Shaun

  8. This plugin seems to be huge, thank you!

    This was exactly what I was looking for, injecting some individual meta-tags for special website adjustment.

    Almost every SEO-Plugin lacks editing meta-tags beside keyword- and description-tag. I highly doubt that those coders now the real deal about SEO. ;)

    I will give it a try and if it works out – what I really expect :) – I gonna write a review and recommand it to my dear blog-readers here in good ol’ Germany.

    Have a nice weekend.

    Regards,

    René/ProbloggerWorld.de

  9. Great plugin. I installed it and got it working in a matter of minutes.

    One question: I installed this plugin in order to edit and control the keywords and descriptions for each page/post. In order to do that, I removed the keywords and description lines from the header.php code. But I realized that now my homepage doesn’t have these lines.

    I guess my question is: can there be, for instance, 2 keywords lines, one general that appears on the homepage and all post pages, and one with more specific keywords that is just on individual pages? Or is there some problem with doing that?

    Thanks.

  10. hey John. thanks for responding. i guess i thought that that’s what this plugin was for. but if the one you suggest offers more control, i’ll try it and see how it works. thanks. – PAUL

  11. hi John, I’m a little bit confuse over what’s this plugin doing, I was searching for plugin that could insert meta desc /keyword into homepage/archieve pages/ search result, etc. Because the old plugin that I use, can only display meta desc/keyword in the single post pages. This makes my homepage doesn’t have meta desc (SE grab it from the text in my sidebar which is not related to the content), not just the homepage, the archive pages that is indexed by SE also give weird meta desc.

    Can your plugin help me solve this issue John ?

    Thanks

  12. I’m a complete amateur when it comes to PHP and CSS, so this might be a stupid question, but here goes.

    On my site discordian.ca, I installed the plugin (which is great, btw) for the purpose of simply changing the colour of my links (when they are hovered over) on individual posts and pages. To change the links to the colours I desired, I added this to the of a post using the head-meta plugin:

    a:hover {
    color: #ff7800;
    text-decoration: none;

    Everything seems to be working fine on IE and Firefox, but not on Safari, which still displays the links with the regular colour from the main style.css file.

    Here’s the page: http://discordian.ca/poly-see-dept/down-the-memory-hole/

    Thanks in advance. Hail Eris!

  13. Nevermind. I fixed my problem… Why does it always take me seeing my faulty code posted in the comments of some site before I realize I’m missing a stupid } ?

    Sorry to pollute your comments with this crap…

  14. Is your Head Meta Plugin still available? The download link above returns a 404 page.

  15. Thank you, John! I’m excited to give this a try. I’m using the Shifter Theme.

  16. John, I’ve loaded it successfully. I’m looking for a way to add JavaScript to the head of every page on the site. Does this plugin have any “global” options to do this? It appears to be designed for a page-by-page basis.

  17. Dana: This plugin is just for single posts and pages. Adding something to the head of every page is simple but it doesn’t look like there is a plugin out there to do it.

    Try this:

    <?php
    /*
    Plugin Name: Head Stuff
    Description: Head stuff
    Version: 1.0
    Author: John Blackbourn
    */
    function jb_head_stuff() {
    ?>
    <script type="text/javascript"><!--
    // Put all your JavaScript here!
    --></script>
    <?php
    }
    add_action( 'wp_head', 'jb_head_stuff' );
    ?>

    You’ll have to add your JavaScript in manually where it says “Put all your JavaScript here!”.

  18. I don’t have access to the file with this theme. I will inform the developer. He’s open to writing a plugin. I’ll share with you the outcome. THANKS!!

  19. Hey just wanted to thank you for this awesome plugin. It was EXACTLY what i was looking for :D

  20. Thanks, David for the plugin note. I’m bookmarking this for future reference. I’m using the Shifter theme that is a little tricky. The developers took John’s code and revised it to work for Shifter! I’m bookmarking the Header-Footer plugin and can see why it’s rated with 5 stars!

    Thanks also to Ludicrous for great contributions!

  21. Thanks John for taking the time to create this but when I installed it and tried it out (tried inserting some Javascript) I noticed that all the double quotes in the code get escaped (i.e., a backslash is inserted before all double quotes) essentially rendering the code useless. I had to use a ‘plain text’ hack that I worked up a while ago to get WordPress to stop escaping double quotes when using your plugin. Is there something I’m missing? Because nobody else has mentioned this.

  22. That’s odd Rob, there’s no reason why the double quotes should be getting escaped as the plugin only uses WordPress’ built-in functions for displaying the content on the page.

    I can’t reproduce the problem. What version of WordPress are you using?

  23. I tested it on two different sites (and themes) using WordPress 2.6.1. I also tested in both Firefox 3 and Internet Explorer 7 to see if it was a browser specific problem. Same results. All double quotes get escaped. I also tried disabling any plugins which I thought might be creating a conflict and still the same. I’m still going to use your plugin as it’s very useful but I’m still wondering how everybody else manages to use it without having to apply a hack to get WordPress to stop escaping double quotes.

  24. How can i show the full post in the main page without click in the permanlink?

    i want to show a full post in the index, just one and the most recent without click in the title, i want to use this plugin to put some JavaScript in one post, but i want to show up without clicking in the title so i don’t know if is possible to see
    “www.myblog.com/2009/01/05/sample-post/” JavaScript in “www.myblog.com”

    sorry for my english =S

  25. Thanks for this plug in in. Needed to be able to set a cookie just on my contact form page and this was exactly what I needed.

Comments are closed.