How to Remove JQuery From WordPress (Front-end and Back-end)

JQuery is one of the heaviest loading assets of a WordPress site. When testing your site on the Google Page Insights tool, it suggests removing unused JavaScript. To fix this error, you can remove jQuery from your website.

I use Ezoic extensively on my sites for monetization and page speed optimization. Ezoic always recommends that WordPress users never use the jQuery JavaScript library, as it slows down the site.

jQuery is a JavaScript library included in WordPress by default. A lot of plugins and themes make use of jQuery libraries for offering different features. JQuery script loads around 35KB of js when zipped. The unzipped version can go beyond 100KB. This is why jQuery is termed as one of the heaviest loading assets on your site.

That is why it is recommended that you remove jQuery from your site.

First of all, make sure that any plugins or your WordPress theme are not using the jQuery on the front-end of the website. Otherwise, if jQuery is being used, some features will stop working on the site.

You should always use a light-weight fast theme like GeneratePress. We also recommend Themify themes that use jQuery, but the themes are feature rich.

You can remove jQuery using WordPress plugins, but I don’t prefer the plugins, as they put an extra load on our installation. So I will share a simple method to remove jQuery from your site.

If you prefer to use the plugins, the following plugins have the option to remove jQuery from your site:

If you are using Ezoic LEAP, it will automatically optimize the loading of jQuery from CDN so your site loads faster.

Remove jQuery

To completely remove jQuery from the front end of your site, copy and paste the following code into your theme’s functions.php file:

/* Remove jQuery from WordPress Frontend */
function remove_jquery() {
if (!is_admin()) {
wp_deregister_script('jquery');
wp_register_script('jquery', false);
}
}
add_action('init', 'remove_jquery');

We remove jQuery from the WordPress front-end only because the WordPress admin uses it. You can also remove it from the backend but it is not recommended. You can remove the jQuery library altogether using the following code in your theme’s functions.php.

/* Remove jQuery from WordPress frontend and backend */
add_action('wp_enqueue_scripts', 'remove_jquery');
function remove_jquery(){
    wp_deregister_script('jquery');
}

I have tested this code on WordPress 5.9 and it is working perfectly fine.

If you prefer a plugin instead of manually putting the code, you can use the Remove jQuery plugin. It has not been updated for a long time, but essentially it does the same thing as the above code. So there is no issue using this plugin. I have tested the plugin and it works fine on WordPress 5.9. Please note that this plugin will only remove jQuery from the front-end. The backend will continue to work without any problems.