Sign up ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I am using the following code below in my functions.php, However app.js is not found when I inspect it in the resources tab.

It is looking for it in http://localhost:8888/goodMorningMoon/javascripts/app.js?ver=3.3.1

when it should be looking in http://localhost:8888/goodMorningMoon/wp-content/themes/Good-Morning-Moon/javascripts/app.js?ver=3.3.1

How do I modify this code so it looks in the correct directory, do I need to add get_template_directory_uri(); somewhere, I have tried but to no avail.

Thanks in Advance

p.s this is located in my functions.php file, since I read from here that that is the proper way to approach including js files.

function load_scripts() {
   wp_enqueue_script('my_javascript_file', '/javascripts/app.js', array('jquery'));

add_action('init', 'load_scripts');
share|improve this question

1 Answer 1

up vote 5 down vote accepted

You need to reference your WordPress template directory when you register the script.

Change this:

wp_enqueue_script('my_javascript_file', '/javascripts/app.js', array('jquery')); this:

wp_enqueue_script('my_javascript_file', get_template_directory_uri() . '/javascripts/app.js', array('jquery'));

Codex reference: get_template_directory_uri()

share|improve this answer
thanks I thought it was something like that, I just couldn't get the syntax right. Do you know why I need array('jquery') it doesn't make sense to me. – Anders Kitson Mar 11 '12 at 19:26
@AndersKitson that's a dependency. – soulseekah Mar 11 '12 at 19:37

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.