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

I thought I had read it was possible to use wp_enqueue_script() and wp_dequeue_script() directly in individual template files. However, when I add

  wp_dequeue_script( 'myscript' );

to the top of page.php, myscript still gets loaded.

Is it possible to do what I'm trying to do?

share|improve this question

Script dequeuing calls should be added to the wp_print_scripts action hook, like so:

function example_dequeue_myscript() {
   wp_dequeue_script( 'myscript' );

This is because scripts are typically enqueued on the wp_enqueue_script hook, which happens early in the wp_head process. The wp_print_scripts hook happens right before scripts are printed, and thus is latest in the process.

share|improve this answer
So is it not possible to use wp_dequeue_script directly in a template file? – supertrue Sep 12 '12 at 1:09
It's possible, but the effectiveness of it will be determined by how the plugin/theme enqueues the script. The method I give should work in the majority of cases. – Otto Sep 12 '12 at 3:04
Thanks, works fine for child themes and also for stylesheets. (action: wp_print_styles and function: wp_dequeue_style) – Diana Aug 31 '13 at 17:16

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.