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

JQuery Conflicts WordPress


I have some jquery scripts loaded in the following manner:

function jules_scripts() {
if (!is_admin()) {
wp_register_script('superfish', get_template_directory_uri() . '/js/superfish.js', 'jquery');
wp_register_script('easing', get_template_directory_uri() . '/js/jquery.easing.1.3.js', 'jquery');
wp_register_script('tz_custom', get_template_directory_uri() . '/js/jquery.custom.js', 'jquery', '1.0', TRUE);
wp_register_script('jquery-ui-custom', get_template_directory_uri() . '/js/jquery-ui-1.8.5.custom.min.js', 'jquery');

add_action('init', 'jules_scripts');

However, when I try to then also load my cufon scripts and a scroller script it stops the other menu scripts working:

I thought by adding the following it would include cufon:

wp_enqueue_script( 'cufon-yui', JULES_JS .'/cufon-yui.js', 'jquery');
wp_enqueue_script( 'colaborate', JULES_JS .'/DejaVu_Sans_Condensed_400.font.js', 'jquery');

Perhaps I am calling the scripts incorrectly in the first place.

Answers (2)


Daniele Raimondi answers:

You have to register your scripts before yo can enqueue them. Try to add calls to <strong>wp_register_script</strong> as for the others scripts above.

wp_register_script('cufon-yui', JULES_JS .'/cufon-yui.js', 'jquery');
wp_register_script(colaborate', JULES_JS .'/DejaVu_Sans_Condensed_400.font.js', 'jquery');

wp_enqueue_script( 'cufon-yui');
wp_enqueue_script( 'colaborate');

by the way, can you post a link to the page where those script should load?

oh, a little suggestion: append this code to the footer.php of your theme

<script type="text/javascript">if(typeof Cufon == 'function') {;} </script>

(but eventually before a google analytics call) for Internet Explorer, otherwise there will likely be a short delay before Cufón does its thing. Applies to other browsers as well in case you’ve got any external scripts in the <body> of the document.


John Cotton answers:

You might want to make more use of the dependency parameter in the registration.

So, for example, if the DejaVu font needs cufon to work, register it like this:

wp_register_script(colaborate', JULES_JS .'/DejaVu_Sans_Condensed_400.font.js', array('jquery', 'cufon-yui'));

and then you only need enqueue the one script:
wp_enqueue_script( 'colaborate');

which will make sure that the Cufon script appears before the Collaborate script.

Without seeing your page it's difficult to know, but I imagine that you could do that for your tz-custom script thus ensuring that scripts were loaded in the desired order.