Remove a script from a template file using wp_dequeue_script

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

add_action('wp_print_scripts','example_dequeue_myscript');
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.

Leave a Comment