Bobcares

Deregister Script WordPress jQuery | How to remove it?

by | Dec 31, 2022

In this article, we will see the steps to remove jQuery using the deregister script method in WordPress. Bobcares, as a part of our WordPress Support Services, offers answers to every query that comes our way.

How to remove jQuery using the deregister_script() in WordPress?

Removing jQuery completely has its own set of downfalls. To function properly, many plugins and themes rely on jQuery. So we have to look into the theme and make sure to select one that does not rely on jQuery, such as the free GeneratePress. To completely remove jQuery from the WordPress installation, add the following code to the functions.php file in the theme folder. Else, create a functions PHP plugin.

/** * Completely Remove jQuery From WordPress */
function my_init() {
    if (!is_admin()) {
        wp_deregister_script('jquery');
        wp_register_script('jquery', false);
    }
}
add_action('init', 'my_init');

We can also remove WordPress’s default jQuery from the front end. When we try to customize the theme, this other code prevents conflicts with jQuery. To remove the default jQuery, add the following code to the function.php file.

/** * Completely Remove jQuery From WordPress Admin Dashboard */
add_action('wp_enqueue_scripts', 'no_more_jquery');
function no_more_jquery(){
    wp_deregister_script('jquery');
}

Removing jQuery Migrate using the deregister_script method in WordPress

To support older jQuery versions in un-updated themes and plugins jquery-migrate.min.js is loaded by WordPress. Almost all themes and plugins no longer make use of these files. The removal of these files will improve the site’s performance. We can remove jQuery Migrate in 2 ways.

Removing jQuery Migrate using plugins in WordPress

We can use Remove jQuery Migrate By Hendy Tarnando or premium plugin Perfmatters to completely disable jquery-migrate.min.js. In the case of Remove jQuery Migrate By Hendy Tarnando plugin, we just need to enable the plugin. And for Perfmatters plugin, we have to activate the plugin and then enable the Remove jQuery Migrate option and it’s done.

Removing jQuery Migrate without plugins in WordPress

In order to disable this jquery-migrate.min.js from the WordPress site, we have to include the below code inside the function.php file:

function functionname_remove_jquery_migrate( $scripts ) {

if ( ! is_admin() && isset( $scripts->registered['jquery'] ) ) {

$script = $scripts->registered['jquery'];

if ( $script->deps ) {
$script->deps = array_diff( $script->deps, array( 'jquery-migrate' ) );
}
}
}
add_action( 'wp_default_scripts', 'functionname_remove_jquery_migrate' );

 

[Need help with another WordPress issue? We’re happy to help.]

Conclusion

The article provides a simple and easy solution for removing jQuery using the deregister script method in WordPress.

PREVENT YOUR SERVER FROM CRASHING!

Never again lose customers to poor server speed! Let us help you.

Our server experts will monitor & maintain your server 24/7 so that it remains lightning fast and secure.

GET STARTED

0 Comments

Submit a Comment

Your email address will not be published. Required fields are marked *

Never again lose customers to poor
server speed! Let us help you.