Ask your WordPress questions! Pay money and get answers fast! Comodo Trusted Site Seal
Official PayPal Seal

WP jQuery enqueue strangeness with Gravy framework WordPress

  • REFUNDED

I'm having some trouble with the Gravy WordPress theme and the enqueuing of scripts. The enqueued jquery from wp_head works fine for the superfish menu, but not for any other jquery plugins I might add on a site. However, if I link to the Google API copy of jquery in the header, everything works. However this of course bothers me as its another 55kb of weight to load jquery twice, its pretty pointless to load the same script twice. I've also tried a hardcoded link to the wordpress copy of jquery and that doesnt work either. Anybody have any similar experiences/solutions?

Answers (2)

2010-04-24

Merne Asplund answers:

This may not help your size issue, but it will ensure you dont have a bunch of jquery versions on the loose.

Use wp_head() as a reference point. This goes in your theme.


<?php wp_head(); ?>

<?php wp_deregister_script("jquery"); ?>

<?php wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4/jquery.min.js' ); ?>




of course you can change the jquery repository if you wish.

2010-04-24

Milan Petrovic answers:

Problem is most likely due to compatibility mode of jQuery. I will check this theme to see what is actually loading, maybe that is the problem, and I will get back to you.


Milan Petrovic comments:

Well, Gravy theme loads proper jQuery bundled with WordPress. This should work with any other jQuery script as long as the script is compatible with loaded jQuery (1.3.2 in WP 2.9, and 1.4 in WP 3.0). I never load external jQuery, only the one bundled with WP and I always have a lot of jQuery code, and everything works fine.


James Beardmore comments:

Here is a new wordpress install with the theme pretty much unchanged. If its any use to anyone. http://dev.pointydesign.com/oo0410

You can see that the superfish menu animations work fine but the slidedeck on this page http://dev.pointydesign.com/oo0410/?page_id=3 doesnt work unless I hardcode a link to the google version of jquery.

I know its something to do with the theme, its a great framework if only I could work this out!


James Beardmore comments:

Sorry I just missed your reply. Take a look at the site above and you can see that even though jQuery is in the header and working fine for superfish the slidedeck, a jquery plugin I added, is not working. If I add a hardcoded link to jquery it works...


Milan Petrovic comments:

Well, I opened slidedeck.jquery.js JavaScript with Firebug in Firefox and it was filled with non printable characters that can't be parsed properly, and that's why it fails. Try to use non compressed version of that file. Maybe jQuery 1.4 can work with that, but jQuery 1.3 surely can't. It's best to compress file again using some proper compressor like: http://javascriptcompressor.com/


James Beardmore comments:

I have just added the google API link to jQuery in the head and you will see that slidedeck now works fine. However yes I was surprised by the characters in slidedeck.


Milan Petrovic comments:

SlideDeck is definitively the problem due to unusual characters in compressed version. My advice is to re-compress it properly and use jQuery bundled with WordPress, because as it looks right now SuperFish is not working on your website, because jQuery from GoogleCode doesn't have compatibility mode set.


James Beardmore comments:

I disagree. That is the state that slidedeck somes when downloaded and works perfectly offline and on many other sites in that state, it was also working perfectly just when I added the hardcoded jQuery link. I agree it needs different compression but its not causing the problem. Also, this happens with any jQuery I try to add into this theme. With any other WP theme I don't have this problem, even when enqueueing scripts.

Superfish doesnt work if I add the hardcoded jquery link, if I remove it you will see that slidedeck now doesnt work but superfish does.


Milan Petrovic comments:

There is nothing wrong with the theme. Problem is this file. Firebug reports errors in it, and not in jQuery or SuperFish. Compressed files shouldn't look like that. Superfish will not work with jQuery from Google no matter what else you do.


James Beardmore comments:

I'm going to remove slidedeck and replace it with another jQuery plugin tomorrow and you will see exactly the same thing happening, I have it happening on 3 sites right now with different jquery plugins. Some are totally uncompressed, others are minified etc. I'm not going to put them on here for reasons of confidentiality with clients.