nooshu - Matt Hobbs' Web Development Blog

Kneeling on the shoulders of giants

Headspace2 JavaScript error

Update: An update of Headspace2 has just been released that seems to solve this issue as well as a few others.

After updating to WordPress 3.0 (yay!) I decided to check the plug-ins that I’ve written to see if they still worked in version 3.0; to my dismay Post Thesaurus had stopped working… nooooo! Not good! A quick scan using Firebug revealed the issue: the Headspace2 plug-in.

Headspace2 is a superb plug-in that allows you to tweak the SEO potential of your site. There are tonnes of options available; All In One SEO is easier to use, but I prefer the flexibility of Headspace2. The problem was occurring in the headspace-tags.js file:

1
2
3
$(get_tag_element()).val() is undefined
/wp-content/plugins/headspace2/js/headspace-tags.js?ver=3.6.32
Line 76

This error was stopping the rest of the JavaScript on a post page from firing (hence breaking Post Thesaurus). Looking at line 76 of headspace-tags.js you will see:

1
2
3
4
5
// Highlights headspace tags using the WordPress tag field as source
function highlight_tags () {
    var words = $(get_tag_element()).val().toLowerCase().split(',');
    //...
}

The code seems to be falling over when there are no tags, so I just added a ternary operator which checks the array length first.

1
2
3
var words;
var wordArray = $(get_tag_element());
(wordArray.length) ? words = $(get_tag_element()).val().toLowerCase().split(',') : words = [];

If there are no tags create an empty array, else run the usual code. Adding this code fixed the issue and Post Thesaurus works again. Phew! Panic over. I’m sure this error will be picked up by the developer straight away and fixed in the next update.

Rik on June 18 10 / 168 Permalink

I’ve been puzzling for hours to fix this, my complete WP edit-post pages didn’t work anymore. Copied your code and now things work fine again.

Thanks a lot for saving my day :)

Matt on June 18 10 / 168 Permalink

Hey Rik, Glad it helped! Caused a bit of a headache for me to!

Rik on June 20 10 / 170 Permalink

Hi Matt, do you also have the problem that the category fields for Headspace 2 have disappeared on the edit category pages? So far I heard from one other person who had the same problem… mine are missing anyhow.

But the major problem was the breaking up of the edit posts section, and that problem is solved thanks to your code ;)

Matt on June 20 10 / 170 Permalink

Hi Rik,
I haven’t seen this problem myself; but maybe I’m looking in the wrong place. Where would I find the “edit categories” page? If you point out where the page is i’ll have a look see if it is a quick fix.

Rik on June 20 10 / 170 Permalink

Hi Matt.
When you go to Posts > Categories from the dashbaord you can select a category to edit. There you’ll find the Name, Slug, Parent and Description fields. Normally with Headspace2 installed you’ll find additional fields there (Title, Meta Description, Meta Keywords etc.). With WP3.0 these additional fields are gone on my install…

Matt on June 20 10 / 170 Permalink

Hi Rik,
Yes I see what you mean, I’d never noticed that feature before. No extra data under edit categories. It isn’t a JS error,looks to be a core plug-in issue. I’ll try having a look over the plug-in later, see if there any obvious issues. Hopefully the plug-in will be updated to WP 3.0 soon…

Rik on June 20 10 / 170 Permalink

Haha, a well hidden feature then ;) It comes in very handy for SEO though. I’ll just wait for an update from Urban Giraffe. Just wanted to be sure it had nothing to do with me, but since more people have this issue now I’m pretty sure it’s a HeadSpace2 bug.

Thanks and enjoy the weekend!!

Jason on June 21 10 / 171 Permalink

Thank you very much!

Simon on June 25 10 / 175 Permalink

I’d just gone through my plugins switching them on one by one to figure out where the problem lay and narrowed it down to Headspace. A quick search revealed this very helpful solution and everything’s back to normal!

Thanks very much!

מאמרים on July 9 10 / 189 Permalink

The category fields are now back, however you can’t save any data in them…
Anyone has a solution for this?

Miha J on August 12 10 / 223 Permalink

מאמרים, I have this same problem. Can’t save data to category fields in WP3.0. Is there a known solution?

Ben on August 21 10 / 232 Permalink

Same issue, can’t save data to category fields in WP3.0. Please help

Matt on August 22 10 / 233 Permalink

Sorry Guys, I don’t actually support the plug-in as it isn’t one I’ve created.You best bet is to report the issue to the original authors at http://urbangiraffe.com/plugins/headspace2/.

Hopefully it is a quick fix but I see the plug-in hasn’t been updated since the end of June so maybe the author has gone a little AWOL.

Leave a Comment

Your email will not be published. Required fields are marked *