WordPress: Enqueue jquery.min.js instead of jquery.js

While caching plugins will often take care of this for you, if you want to know how to load up the native, minified version of jQuery that comes with WordPress instead of just loading up jquery.js, here’s how you can do just that:

// enqueue the jquery.min.js that comes with WordPress
function cn_enqueue_wp_jquery_min() {
wp_enqueue_script('jquery', '/wp-includes/js/jquery/jquery.min.js', array(), null, true);
add_action('wp_enqueue_scripts', 'cn_enqueue_wp_jquery_min');

The following is not copy and paste code – it’s just to explain what all is happening.

'jquery', // when we keep this 'jquery' handle, other scripts that require jQuery will still load it as per WP standards
'/wp-includes/js/jquery/jquery.min.js', // this should point to the actual jquery.min.js file, if WordPress is in a sub-directory, you may need to change this a bit
array(), // this handles dependencies, for which we have none
null, // this prevents the script from being called with a version, like ?v=6.5.1
true // set this to false to load the script in the <head> section instead of via wp_footer

Aside from the inline comments in the code above, what we’re essentially doing here is:

  1. The function cn_enqueue_wp_jquery_min() deregisters the regular jquery.js
  2. …and enqueues jquery.min.js included with WordPress by default.

A little less bloat!

Or we could all agree that it’s time we moved to Vanilla JS, because seriously, it’s 2024 and it’s bad enough that WordPress plugins, like Woocommerce, are dropping dozens of scripts into so many sites these days. Google and people like fast sites. This is how the dinosaurs went exctinct people.

PS. That Vanilla JS site is just a joke, it’s just a way of saying “use the Javascript that’s already built into every single browser these days.

Up Next: Is GoDaddy Actually a "Managed WordPress Host?"