wp_dequeue_script()
Cancels the connection of a script that was previously added to the queue.
Since the function cancels the queued script, it needs to be called after the script has been added to the connection queue. If wp_dequeue_script() is called before the script to be canceled is added to the queue, the function will not work and will consume resources unnecessarily.
Scripts are added to the queue using the function wp_enqueue_script().
Use wp_deregister_script() when you need to completely remove a script from the global script registration data, not just remove it from the queue.
No Hooks.
Returns
null. Returns nothing.
Usage
wp_dequeue_script( $handle );
- $handle(string) (required)
- The name of the script to be removed from the output.
Examples
#1 Demonstration of use
Suppose we have a jQuery script on our site, but for some reason we don't need it. This example shows how to disable the jQuery script:
add_action( 'wp_print_scripts', 'de_script', 100 );
function de_script() {
wp_dequeue_script( 'jquery' );
wp_deregister_script( 'jquery' );
} #2 Dequeue a script
For example, there is jquery-ui-core script on our page, but we don't need it, let's remove it.
add_action( 'wp_print_scripts', 'wpdocs_dequeue_script', 100 );
/**
* Dequeue the jQuery UI script.
*
* Hooked to the wp_print_scripts action, with a late priority (100),
* so that it is after the script was enqueued.
*/
function wpdocs_dequeue_script() {
wp_dequeue_script( 'jquery-ui-core' );
}
Notes
Changelog
| Since 3.1.0 | Introduced. |
wp_dequeue_script() wp dequeue script code WP 6.8.3
function wp_dequeue_script( $handle ) {
_wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle );
wp_scripts()->dequeue( $handle );
}