How to remove jQuery from loading in your WordPress site

How to remove jQuery from loading in your WordPress site

Increasingly the web is moving away from jQuery. The library that came to be a part of the majority of the entire internet, is now seen largely as a relic. And that’s because faster methods for doing most of the same things have been developed. Plain JS, or vanilla JS, isn’t so plain anymore. Nearly any of the main functions we might really use in jQuery can be done without jQuery and without any library.

Many of the apps and major sites that you use everyday now use either React, Vue or other Javascript frameworks. Yet WordPress still loads jQuery by default, and unfortunately it will take years to remake all the themes and plugins that rely heavily on it.

Starting in WP 5.x with the new Gutenberg editor, came the emergence of the shift toward modern JS in WordPress. React is now baked into WP and available through a global wp.element. Both React and React-Dom are automatically available in any WP site. Developers just need to load them, and learn some of the unique aspects of using React inside a WP environment.

Removing jQuery from your front-end is actually easy to do. The problem is on most WP sites it will likely break your theme, and most if not all of your plugins. Other than this, you’ll be fine. Removing jQuery at this point, probably isn’t practical for most sites. But if you’re a developer working on a new site, if you have the luxury of building a custom theme, you just might be able to entirely eliminate reliance on jQuery and build your front-end features from either straight JS or a modern JS framework such as React or Vue.

// remove from front end only 
if ( !is_admin() ) wp_deregister_script('jquery');

// remove everywhere (not recommended because it may break the WP Admin
wp_deregister_script('jquery');

Credit to the thread below for the code snippet:

https://stackoverflow.com/questions/1157531/how-can-i-remove-jquery-from-the-frontside-of-my-wordpress

Leave a Reply

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

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

admin

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut elit tellus, luctus nec ullamcorper mattis, pulvinar dapibus leo.

admin