How To Completely Remove jQuery From WordPress

How To Completely Remove jQuery From WordPress

As you can see this website does not use jQuery. For many years now, WordPress has kept a version of jQuery that has security issues (1.12.4) and is outdated. By completely removing jQuery all errors resulting from it on Lighthouse will disappear. Completely removing jQuery also has its drawbacks. Many plugins and themes use jQuery to work properly. So just pay attention to the theme and make sure you choose a theme that has no dependencies on jQuery such as free GeneratePress. In order to completely remove jQuery from your WordPress add the following code in the functions.php file in the theme folder or, alternatively, create your own 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 default WordPress jQuery from the front-end. This other code avoid conflict with the jQuery in your theme when you try to customize it. In order to remove the default jQuery add the following code in the function.php

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

If your goal is to update the current version of jQuery 1.12.4 to the newer version 3.5.1 then you will need to enter the following code in the functions.php file in the theme folder or, alternatively, create your own functions php plugin with personalized functions.

/** * Install latest jQuery version 3.5.1. */
if (!is_admin()) {
	wp_deregister_script('jquery');
	wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"), false);
	wp_enqueue_script('jquery');
}

The functions.php codes are 100% functional and have been revised on 18 September 2020. If you use a server like Synology NAS, removing jQuery or updating it to the latest version will only increase security. Questions, doubts? Contact me using the contact page.

This post was updated on Monday / October 5th, 2020 at 7:31 AM