Removing jQuery from the WordPress Frontend

2024 so far has been all about trying to optimize Extra Chill in the wake of all these Google updates. Like most content sites, we have taken a massive hit to our organic traffic and we are trying to recover.

One of the biggest things for my site was Page Speed. Extra Chill uses the ColorMag Pro theme which I installed in 2018 or so, and then proceeded to customize without a child theme (don’t do this). This meant that back in September 2023, prior to all of my optimizations, I was working with a clunky site on an outdated beginner theme.

Part of my efforts were removing lots of Javascript in order to speed up the site. Eventually, I got to a point where I had removed or consolidated all of my JS files into only what is absolutely necessary to make my site function.

Then, I checked PageSpeed insights and noticed that Jquery.min.js was still being enqueued in the frontend. Since nothing else was using it, I decided to get rid of it.

Disclaimer

Please note that removing jQuery from the WordPress frontend is an advanced technique, and it will break many plugins. It is not recommended, and since writing this post I have since removed the following snippet from my site, because I was tired of tracking down errors only to find that it was broken because I removed jQuery.

However, if you’re absolutely sure that you’ve done your due diligence, it is absolutely possible to remove it from WordPress with nothing more than a simple code snippet.

Also note that the WordPress backend makes heavy use of jQuery as does the admin bar. It is recommended, required, even, to use jQuery in the back end.

Okay, now that I’ve got that out of the way. To remove jQuery from the WordPress frontend, simply add this script to your theme’s functions.php file (or child theme, or custom plugin).

This will save you about 30kb of page data. Every byte counts! But remember, just because you can, doesn’t mean you should.

Code Snippet to Remove jQuery

function remove_jquery_script() {
    if (!is_admin()) { // Ensure jQuery is still loaded in the admin
        wp_deregister_script('jquery');
        wp_register_script('jquery', false); 
    }
}
add_action('wp_enqueue_scripts', 'remove_jquery_script', 11);
← Back to Blog