Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am developing a simple Wordpress app but I am having an issue as all of the plugin scripts are rendered before those which are enqueued in my functions.php.

Here is a sample section of the functions.php:

function my_scripts() {
    wp_register_script('app-js', get_template_directory_uri() . '/javascripts/app.js', array('jquery'), null, true );
    wp_enqueue_script('app-js');
}
add_action( 'wp_enqueue_scripts', 'my_scripts');

The important this to note is that (following best practice my JS is set to render at the bottom of the page.

I also have couple of plugins running on the theme. The problem is that the output looks like this:

<!-- Note the plugin appears first -->
<script type='text/javascript' src='http://localhost/wordpress/wp-content/plugins/my-plugin/acl-plugin.js'></script>
<!-- And the main JS appears second -->
<script type='text/javascript' src='http://localhost/wordpress/wp-content/themes/my-theme/javascripts/app.js'></script>
</body>
</html>

How can I force Wordpress to display the main JS (which I believe is rendered by wp_head() ) to appear above the plugin scripts? That way the plugins can reference JS functions that are in the main theme.

share|improve this question
    
Try and add the priority parameter to the hook for app.js and see if it works. like add_action( 'wp_enqueue_scripts', 'my_scripts', 1 );. By default it is 10, so lets call it early and see if this works for you –  Maruti Mohanty Nov 11 '13 at 19:37
    
your question is a bit confusing, your app.js is at the bottom of the page (output by wp_footer, not wp_head), what's the issue? –  Milo Nov 11 '13 at 19:40
    
Woops, type-o in there. Thanks @Milo what I meant was how to I ensure that the PLUGINS appears below the main script. I'll edit the question now. –  Sheixt Nov 11 '13 at 19:51
1  
@MarutiMohanty thanks for the suggestion. Adding the priority has moved it! Do you want to add this as an answer (so you get the rep) or I can outline the answer for others instead. –  Sheixt Nov 11 '13 at 20:05
    
@Sheixt sure, done :) –  Maruti Mohanty Nov 11 '13 at 20:14

1 Answer 1

up vote 2 down vote accepted

Try and use/add the priority parameter of the hook for app.js and see if it works.

add_action( 'wp_enqueue_scripts', 'my_scripts', 1 );

By default it is 10, so lets call it early and see if this works for you

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.