wp_deregister_script()
Remove a registered script.
Note: there are intentional safeguards in place to prevent critical admin scripts, such as jQuery core, from being unregistered.
No Hooks.
Return
null
. Nothing (null).
Usage
wp_deregister_script( $handle );
- $handle(string) (required)
- Name of the script to be removed.
Examples
#1 Register your jQuery script
Now, suppose we want to change the link from where the jQuery script will be downloaded, we will use google CDN, i.e. the script will be downloaded from google repository:
// jQuery registration add_action( 'wp_enqueue_scripts', 'my_scripts_method' ); function my_scripts_method() { // cancel the registered jQuery // instead of "jquery-core" you can write "jquery", then jquery-migrate will also be cancelled wp_deregister_script( 'jquery-core' ); wp_register_script( 'jquery-core', '//ajax.googleapis.com/ajax/libs/jquery/3/jquery.min.js'); wp_enqueue_script( 'jquery' ); }
#2 Removing the jQuery script
Suppose we need to remove the basic registration of the jQuery script. Then use the following code in the themes functions.php file:
wp_deregister_script( 'jquery' );
#3 Deregistering will not dequeue the script handle in the strict sense.
You may use wp_deregister_script ( 'script-handle' );
followed by wp_register_script()
if you want to change the URL of an already enqueued script without changing the order in which it is enqueued, for example when a parent theme has not specified dependencies correctly.
Notes
- See: WP_Dependencies::remove()
- Global. String. $pagenow The filename of the current screen.
Changelog
Since 2.1.0 | Introduced. |