WordPress GuideHosting → jQuery

WordPress jQuery not defined and how to fix it

Image

The “jQuery is not defined” error in WordPress usually means your site is trying to use jQuery before it has been properly loaded. It’s a common JavaScript error, especially after theme or plugin updates, and can break features like sliders, forms, or dropdown menus.

The good news? It’s fixable once you understand why it’s happening.

Get fast, reliable hosting for WordPress

Power your site with the industry’s fastest, most optimized WordPress hosting

What causes the “jQuery is not defined” error?

This error means that your browser is trying to run a script that uses jQuery, but jQuery hasn’t been loaded yet, or it wasn’t loaded correctly. Here are the most common causes:

How to check if jQuery is loading correctly

Before diving into solutions, make sure jQuery is being loaded on your page:

If it’s missing, failed, or loaded after your script, you’ll need to fix how it’s enqueued.

How to fix jQuery is not defined in WordPress

1. Enqueue jQuery properly in functions.php

WordPress comes with jQuery built-in, but you still have to enqueue it properly:

function my_custom_scripts() {
    wp_enqueue_script(‘jquery’);
    wp_enqueue_script(‘my-custom-script’, get_template_directory_uri() . ‘/js/my-script.js’, array(‘jquery’), null, true);
}
add_action(‘wp_enqueue_scripts’, ‘my_custom_scripts’);

Key points:

2. Don’t load jQuery from an external source unless necessary

Some themes or developers try to load jQuery from a CDN like Google:

wp_deregister_script(‘jquery’);
wp_register_script(‘jquery’, ‘https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js’);
wp_enqueue_script(‘jquery’);

This can break your site if:

Unless you have a good reason, stick with the default WordPress jQuery.

3. Use jQuery instead of $ in your custom scripts

In WordPress, $ is not always available because jQuery is loaded in no-conflict mode.

Instead of this:
$(document).ready(function() {
  // your code
});
Use this:
jQuery(document).ready(function($) {
  // $ now refers to jQuery safely
});

This wrapper makes sure your code works with WordPress without breaking other libraries.

4. Check for plugin or theme conflicts

Sometimes plugins or themes:

To test this:

Once you identify the source, check if there’s an update or contact the developer.

5. Use the right action hook to enqueue scripts

If you enqueue scripts too early (like in init), jQuery might not load in time.

Use the wp_enqueue_scripts action:

add_action(‘wp_enqueue_scripts’, ‘my_custom_scripts’);

This hook ensures scripts are enqueued when WordPress is ready.

6. Defer or async attributes might break jQuery

If you’re using a performance plugin or manually adding async or defer to script tags, it can cause jQuery to load after your scripts that depend on it.

To fix this, exclude jquery.js from deferring or async execution in your performance settings.

7. Check for errors in minified or combined scripts

Minification tools like Autoptimize or LiteSpeed Cache can sometimes break script order.

Try disabling minification temporarily and clear your cache. If the error goes away:

jQuery CDN best practices (if you do need to use one)

If you decide to load jQuery from a CDN, follow these best practices:

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js“></script>
<script>window.jQuery || document.write(‘<script src=”/wp-includes/js/jquery/jquery.js”><\/script>’);</script>

How to prevent the jQuery error in the future

Use browser developer tools and tools like Query Monitor to catch script errors early.

Additional resources

Diagnosing WordPress errors on your site →

Even more common errors, how to troubleshoot them, and how to solve them

WordPress Multisite cookie error (and how to fix it) →

Fix the WordPress multisite cookie error by updating your domain settings and clearing browser cookies.

What is managed WordPress hosting? →

What it means, what it includes, and how to decide if it’s right for you