WordPress enqueue script dependencies

I wrote a plugin for WordPress and I need to enqueue a couple of scripts which require jquery. This is my code:

wp_enqueue_script( 'script1', plugins_url( 'plugin-name/js/script1.js', array( 'jquery' ) ) );
wp_enqueue_script( 'script2', plugins_url( 'plugin-name/js/script2.js', array( 'jquery', 'script1' ) ) );

My problem is that the scripts are loaded, but it seems that the correct order is not respected, since I get the error “jQuery is not defined” in the first script and “Object [object Object] has no method ‘methodName’” in the second script, which calls a function defined in the first script. This happens on WordPress 3.8, while on 3.5 is working correctly though.
Any ideas?

Related posts

Leave a Reply