wp_deregister_script

Home » Functions » wp_deregister_script

WordPress is a popular CMS that allows users to create dynamic websites with ease. One of the key features of WordPress is its ability to use scripts to add functionality to a website. However, sometimes you may need to deregister a script that was previously registered. This is where the wp_deregister_script function comes in.

The wp_deregister_script function is used to deregister a script that was previously registered using the wp_enqueue_script function. This can be useful if you want to remove a script that is causing conflicts or simply no longer needed on a specific page or post.

The syntax for the wp_deregister_script function is as follows:

wp_deregister_script( $handle );

The $handle parameter is the name of the script that you want to deregister. This is the same handle that was used when the script was registered using the wp_enqueue_script function.

Here’s an example usage code:

function remove_my_script() {
    wp_deregister_script( 'my-script' );
}
add_action( 'wp_enqueue_scripts', 'remove_my_script', 99 );

In this example, the function remove_my_script is used to deregister a script called ‘my-script’. The add_action function is used to add the remove_my_script function to the ‘wp_enqueue_scripts’ action.

Overall, the wp_deregister_script function is a powerful tool that can be used to remove scripts from a WordPress website when they are no longer needed.

Learn More on WordPress.org

Register an account to save your snippets or go Pro to get more features.