WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top
function load_my_script(){
wp_register_script( 'my_script', get_template_directory_uri() . '/js/myscript.js', 'jquery' );
wp_enqueue_script( 'my_script', 'jquery');
add_action('wp_enqueue_scripts', 'load_my_script');

myscript.js is loading before jquery, why? And how do I make it load AFTER jquery?


share|improve this question

You have a typo in your code. It should be:

function load_my_script(){
        get_template_directory_uri() . '/js/myscript.js', 
        array( 'jquery' )
    wp_enqueue_script( 'my_script' );
add_action('wp_enqueue_scripts', 'load_my_script');

The jQuery dependency needs to be an array(), not just a string. This will force your script to load after jQuery.

share|improve this answer
... is 'jquery' needed in wp_enqueue_script? – Dave Apr 10 '12 at 17:41
In the wp_register_script function, yes. It tells WordPress that jQuery is needed for this script to run, so it'll be loaded accordingly. In wp_enqueue_script it's not necessary, because WP already knows the dependencies from before. – swissspidy Apr 10 '12 at 17:56
Exactly. Sorry, forgot to remove jQuery from the wp_enqueue_script() call. It's not needed there. – EAMann Apr 10 '12 at 17:59

Your Answer


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.