0

I wondered if it was possible to change the order in which a script is enqueued.

I ask this because I wish to include the HTML5 enabling script but it needs to be included before any styles.

Is there any way to change the order?

I could obviously hard code it into the themes header, but I would prefer to enqueue it.

Thanks for any suggestions you may have.

1 Answer 1

3

You can change the order of the scripts but can't have one script load before anything else. The HTML 5 enabling script is IE conditional so you probably don't want to use wp_enqueue_script as it would load for all browser users which isn't necessary.

It's ok to hard code it in your themes header. Even Twentyeleven does it this way.

Also there is nothing that says it has to be added before any styes. It just has to be before the opening <body> tag.

4
  • Good point, I completely forgot about the conditional comment! Thanks. I guess I will just stick to hard coded then. Would be nice to have a WP function for conditional commented scripts though.
    – Wolfy87
    Commented Aug 25, 2011 at 16:59
  • according to the page you linked, the conditional comment is not necessary since the code checks the browser it's running in.
    – Milo
    Commented Aug 25, 2011 at 17:16
  • Yes but why waste a roundtrip dns lookup and external file load when it's not needed.
    – Chris_O
    Commented Aug 25, 2011 at 17:18
  • not commenting on the wisdom of doing so, just pointing out that it's not required.
    – Milo
    Commented Aug 25, 2011 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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