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 have a few scripts which are being enqueued,

the problem is that I want to force the order of prominece to which these scripts are loaded. There is one in particular which is loaded from a plugin before the theme ones which requires jquery however the plugin does not require jquery (bad dev on the plugin but I'd rather not touch 3rd party code for futureproofing reasons)

is there some way to mess with the enqueue order at runtime?

Thanks very much

share|improve this question
add comment

1 Answer 1

up vote 3 down vote accepted

You just need to enqueue your scripts before plugin does it. You can do it by setting priority to 0 for your hook. For example, do the following:

add_filter( 'wp_enqueue_scripts', 'wpse8170_enqueue_my_scripts', 0 );
// or if you enqueue your scripts on init action
// add_action( 'init', 'wpse8170_enqueue_my_scripts', 0 );

function wpse8170_enqueue_my_scripts() {
    wp_enqueue_script( 'myscript', 'http://path/to/my/script.js', array( 'jquery' ) );
    // my else scripts go here...
}

Setting up priority for your hooks will put it to the beginning of calling queue and your scripts will be added first.

share|improve this answer
    
sorry to be naive but i take it that wpse8170_enqueue_my_scripts_on_init is a custom function with standard enqueue_scripts call in it? –  Alex Jun 13 '12 at 8:51
    
@Alex i have updated my answer, check it out. –  Eugene Manuilov Jun 13 '12 at 9:01
    
This doesn't always work: wordpress.stackexchange.com/questions/91961/… –  Dave Kiss May 23 '13 at 16:44
add comment

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.