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');

If your goal is to update the current version of jQuery 1.12.4 to the newer version 3.3.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.3.1. */
if (!is_admin()) {
	wp_deregister_script('jquery');
	wp_register_script('jquery', ("https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"), false);
	wp_enqueue_script('jquery');
}

The functions.php codes are 100% functional and have been revised on 11 February 2019.  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.

Last Updated on by Marius Bogdan Lixandru