wp_dequeue_script()
Remove a previously enqueued script.
No Hooks.
Return
null
. Nothing (null).
Usage
wp_dequeue_script( $handle );
- $handle(string) (required)
- Name of the script to be removed.
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.7.2
function wp_dequeue_script( $handle ) { _wp_scripts_maybe_doing_it_wrong( __FUNCTION__, $handle ); wp_scripts()->dequeue( $handle ); }