Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

WordPress - load mootools before jquery, with wp_enqueue_script

  • 23-06-2010 08:58AM
    #1
    Registered Users, Registered Users 2 Posts: 6,655 ✭✭✭


    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