Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

WordPress - load mootools before jquery, with wp_enqueue_script

Options
  • 23-06-2010 8:58am
    #1
    Registered Users Posts: 6,509 ✭✭✭


    I am helped a guy add SmoothGallery to his WordPress site. SmoothGallery uses mootools.

    A short while later the guy installed a plugin that uses jQuery. The mootools.js script ended up being loaded after jquery.js and broke SmoothGallery. I used wp_enqueue_script as did the other plugin.

    How do I get mootools to load before jquery?
    This is complicated because jquery is included with WordPress and mootools isn't.
    [PHP]wp_enqueue_script('jquery-ui-core'); // Force the loading of jquery.
    wp_enqueue_script('mootools', 'http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js');
    wp_enqueue_script('jquery', '/wp-includes/js/jquery/jquery.js', array('mootools')); // Make jquery depend on mootools
    wp_enqueue_script('jd-gallery', '/wp-content/plugins/smoothgallery/scripts/jd.gallery.js', array('mootools')); // SmoothGallery depends on mootools.[/PHP]

    This code does not work. jquery is loaded in the header, before mootools and the SmoothGallery scripts. jquery-ui-core is loaded in the footer.

    If I move jquery-ui-core to after mootools it will work, but I cannot control when the jquery-based plugin calls its scripts. It seems to call wp_enqueue_script before my code.

    (I have implemented a hack to insert 'script' tags right after the opening <head> but that isn't ideal)


Comments

Advertisement