I am trying to use a self written script for the jQuery library in my self-made theme, but it's not working. When I simply use script-tags, everything is alright. So it has to be something with wp_enqueue_script and wp_register_script. In the beginning of my code in the index.php I have

    wp_register_script( 'my_name', 'path/to/my/script/script.js'));

I know that normally that has to be written BEFORE wp_head(); but because I am still developing everything, I haven't split my code into various files, I am working straight in the index.php. Do I have to do any other steps before enqueueing the scripts?

3 Answers 3


You want to use wp_enqueue_scripts.

add_action( 'wp_enqueue_scripts', 'wpse_3810' );
function wpse_3810() {
    wp_enqueue_script( 'jquery' );
    wp_register_script( 'my_name', 'path/to/my/script/script.js'));
    wp_enqueue_script( 'my_name' );
  • 1
    Yes, but technically, no earlier than init. Using wp_enqueue_scripts is probably more semantically correct. Jan 6, 2012 at 16:21
  • 3
    Doing enqueue on init is wrong and myth, long propagated by incorrect info in Codex. wp_enqueue_scripts is correct hook to use for that.
    – Rarst
    Jan 6, 2012 at 17:12
  • Oh, good to know. I've changed the code appropriately.
    – v0idless
    Jan 6, 2012 at 17:24

There is a 'wp_enqueue_scripts' hook for this, 'init' is usually not the right choice.


I would recommend you put your code in functions.php as that would be loaded before your index.php

You should also define dependencies so that they are loaded in the correct order.

//wp_register_script( $handle, $src, $deps, $ver, $in_footer );
wp_register_script( 'my_name', 'path/to/my/script/script.js', array('jquery') );

See: wp register script

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.