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

The goal- include my-script.js (dependant on jquery) in my WP theme.

The problem- When I use this code,(in the head element of the header template file) my entire page goes blank when loaded:

<?php wp_enqueue_script( 'jquery' ); ?>

<?php wp_enqueue_script(
     "<?php echo get_template_directory_uri() . "/my-script.js"?>",

Have commented out all of my javascript except for an alert, and the javascript works fine on non-WP webpage. So the problem is not there.

I have tried putting the code in functions.php, wrapping the enqueue scripts in a function triggered by init, a la source 1 and other sources,

that approach failed to load the script at all.

More confusingly, according to the codex here, the usual approach of calling the script as I would in an HTML document is fine. And this approach, (skipping wp_enqueue_script), does load my-script.js just fine.

Do I need to use the wp_enqueue_script to include javascript files in my theme, and if so, What am I doing wrong that causes the whole page to disappear on load?

First-time poster, thanks for your patience!

share|improve this question
up vote 0 down vote accepted

You don't need to enqueue jquery if it's already being referenced in my 'my-script'. Also you're running php within php, so you can change this:

"<?php echo get_template_directory_uri() . "/my-script.js"?>",


get_template_directory_uri() . "/my-script.js",
share|improve this answer
I think that was the issue, thank you for the fast response! – Paradasia Jan 12 '12 at 0:15

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.