views:

608

answers:

2

Having a bit of trouble using jQuery plugins (Superfish, jQuery UI, etc) using Wordpress. Everything works fine in my plain non-Wordpress site, but Wordpress seems to conflict with JQuery. There must be some way to get around this.

Also, I'm using Carrington Framework, if that makes a difference.

In Safari's web inspector, I get these errors:

ReferenceError: Can't find variable: jQuery
ReferenceError: Can't find variable: $
+1  A: 

Wordpress and jQuery wouldn't conflict with each other. Wordpress is on the server, jQuery is on the client and aside from dealing with the HTML returned by Wordpress the two don't really have much to do with each other. You would get that error if the javascript that defines the jQuery object wasn't properly loaded / parsed by the browser. Three troubleshooting solutions:

  1. Check and make sure that your client is making the request for the jQuery javascript file. If not then the script tag requesting the file may not be included correctly in your page.
  2. If it is making the request, make sure it's successful. If the response is a 404 code or some other error, fix whatever is causing it (bad url, incorrect permissions, ect.)
  3. I've noticed that when using the minified version of jQuery, the browser occasionally throws an error when trying to parse the code, leading to the reference error you are experiencing when you try to use the jQuery function later in the code. If you are using the minified version of jQuery, try switching to the uncompacted version and see if that solves your problem.
Ryan Lynch
Not necessarily true. jQuery is included in the WordPress admin pages. In addition, some themes may include JS libraries like Prototype that would conflict.
ceejayoz
jQuery loads fine, as do all of the plugins, and the code that I wrote. Will try not using the minified version of jquery ui.
Tim
You say everything loads fine...when are you getting the error then? I would you should be getting the error when the browser tries to execute `$(window).load()` function. My guess is it's the third thing, and there is something about the minified jQuery that Safari doesn't like.
Ryan Lynch
+1  A: 

Just put all of your js under the

<?php
    wp_head(); 
?>

section. If you have any problems in individual files, all the line:

var $j = jQuery.noConflict();

to the top.

Tim
If `jQuery.noConflict()` changed anything it means you have some other object in the DOM trying to use the name `$`. Are you using another javascript framework on your page?
Ryan Lynch