jQuery Is Not Defined WordPress Error: 6 Ways To Fix It

Nightmare. Your WordPress site is down, and when you open up your browser’s console log, a strange message appears:

“Uncaught ReferenceError: jQuery is not defined.”

What on Earth does that mean? What’s causing it, and how can you fix it?

Time is ticking, and customers are waiting.


GIPHY

So, let’s fix the jQuery is not defined WordPress error in this lightning-fast tutorial. That might mean getting a bit technical, so if you’d rather ask for help from a developer, StateWP is on standby.

What Is the WordPress jQuery Is Not Defined Error?

The jQuery is not defined WordPress error occurs when your WordPress website tries to use a jQuery code function, but the jQuery.com JavaScript library is unavailable or isn’t functioning correctly.

It can crash your website because of corrupted WordPress plugins or jQuery files, hosting issues, or CDN problems. In plain English, your website can’t communicate with its library because of broken or conflicting code.

5 Common Causes of the jQuery Is Not Defined Error in WordPress

Seeing “Uncaught ReferenceError jQuery is not defined” in WordPress is pretty common. Here’s what’s likely causing the problem:

  • Your WordPress themes or plugins are corrupted or conflicting: If you recently installed or added a new theme or plugin, it could be conflicting with old plugins – or you need to update them
  • There are errors with your JavaScript or jQuery file: If you download a jQuery file from a potentially shady or incompatible website, errors can arise, such as this or Uncaught TypeError
  • A JavaScript file isn’t running correctly: A JavaScript error could cause your website’s JavaScript code to run before jQuery loads – this is a dependency error where your site’s code is asking questions that don’t have answers yet
  • Your CDN-hosted jQuery might be blocked: If you run jQuery through a popular CDN (Content Delivery Network), it could be overloaded or temporarily out of action
  • Your host is running slow or performing poorly: If your host controls your jQuery, it could be they’re underperforming – which is why it’s essential to use a reputable, private hosting server

6 Ways To Fix the “Uncaught ReferenceError: jQuery Is Not Defined” WordPress Error

Now you know why this error is likely occurring, it’s time to fix it and get your site back live again.

Let’s take this one step at a time.

Start by creating a site backup if you need to reload or if something goes wrong. We recommend setting automated backups if you haven’t done so already, so make sure to do so in case these issues repeat in the future.

Beyond this, we also suggest running any changes you make to your site through a staging environment so you don’t make any edits to your live site while troubleshooting. Web hosts like WPEngine offer staging environments as part of their packages, so ask your provider for advice.

Finally, ensure you have access to an FTP or File Transfer Protocol client, like FileZilla. This program helps you edit code behind the scenes, and you can get login details from your host.

Remember, if you don’t have the time to fix this error yourself or if you’d just prefer expert developer support, you can skip ahead and contact StateWP.

Steps to fix the jQuery is not defined WordPress admin error: A summary

TipIn brief
1. Check jQuery is includedView your website’s source code and look for jQuery – if it’s unavailable, add code to wp-includes through an FTP client
2. Check jQuery is loading correctlyLook for “jQuery” in your source code, and if you can’t see it, move to step three
3. Set up an alternate, local fallback for Google-hosted jQueryUse code to switch your website to Google’s jQuery as a safety net
4. Insert a snippet into wp-config.phpEdit wp-config through your FTP to ensure your website knows jQuery is available
5. Manually add the jQuery library to header.phpIf step four doesn’t work, edit your theme’s header in FTP or use a plugin to add the library from scratch
6. Alternatively, call an expertContact your web host or call a StateWP developer to reconnect your library and bring you back online

1. Check jQuery is included

To start, check that your website’s code includes a jQuery library. WordPress typically installs this for you.

Right-click anywhere on your web page and select “View Page Source” to open the source code.

You should find the code that makes up your page. From here, press CTRL and F keys together on Windows or CMD and F keys on Mac to open a search bar.

Search for “jquery.min.js.” The phrase should appear in the code if your website has a library installed.

If it doesn’t, try checking the Network tab of your browser’s dev tools to see if you notice any jQuery takes being loaded.

If you still don’t see anything, then open FileZilla and log in.

In your root folder, typically “public_html,” look for a folder called “wp-includes.”

Open it, and then open the file called “script-loader.php.”

In the code, search for a line that starts “wp_enqueue_script.” After the word “script,” paste the following (shown in bold):

wp_enqueue_script( ‘tt-mobile-menu’, get_template_directory_uri() .
‘/js/mobile-menu.js’, array(‘jquery’), ‘1.0’, true );

 

If you can log into WordPress, you could also use a plugin like Code Snippets:

You can then add code to your site using this plugin without editing text files.

Now, go back to your website (or the staging version) and see if the problem is resolved.

2. Check jQuery is loading correctly

We now need to check if jQuery is loading as expected. To start, right-click anywhere on your web page and select “View Page Source.”

Then, search for queries in the code that start with “<script src=” and include “jquery” in the same lines. You can, again, do this using CTRL and F or CMD and F.


Source

If you can see lines in the code matching this description, it’s likely loading correctly.

Move to the next step if you can’t see any matches.

3. Set up an alternate, local fallback for Google-hosted jQuery

A CDN, or Content Delivery Network, might be to blame for your jQuery woes. This is a series of networked servers that speed up WordPress but can sometimes cause functionality issues if it goes down unexpectedly.

So, it’s worth setting up a Google-based jQuery you can fall back on now and in the future. To do this, you add the following code:

// Fall back to a local copy of jQuery if the CDN fails
<script>
window.jQuery || document.write(‘<script src=”mysite.com/wp-content/themes/my_theme/js/query.min.js”><\script>’))
</script>

 

Save, and check your site once again.

4. Insert a snippet into wp-config.php

If still no joy, it’s time to edit your site’s configurations. Head back to FileZilla and look for the wp-config.php file in your root folder.

Right-click and download the file to your preferred drive so you have a manual backup, and open the file in your root folder to begin editing.

Look for the following line:

/* That’s all, stop editing! Happy blogging. */

 

Paste the following above that line:

/** Absolute path to the WordPress directory. */
if ( !defined(‘ABSPATH’) )
define(‘ABSPATH’, dirname(__FILE__) . ‘/’);
define(‘CONCATENATE_SCRIPTS’, false);

 

You just defined the ABSPATH, which helps your website recognize that jQuery is available. Save the file and reload your website.

5. Manually add the jQuery library to header.php

If step four didn’t solve the issue, try adding the jQuery library manually. Head to Google Hosted Libraries.

Here, copy the code snippet for the latest version of jQuery from the link above, for example, the snippet listed under “3.x snippet.”:

<script src=”https://ajax.googleapis.com/ajax/libs/jquery/3.7.1/jquery.min.js”></script>

 

Now, find the folder marked “wp-content” in your root folder in FTP, then “Themes,” then the folder marked with the name of the theme you’re using.

In this theme folder, you should see the header.php file. Right-click and save this to your usual drive, and open the version in FTP.

Then, paste the snippet below the tag marked “, save, and reaccess your site.

If you can still access the dashboard and you’d prefer a plugin to edit your header.php via WordPress, we recommend “Insert Headers and Footers” by WPCode.

Install the plugin through the link above, activate it, and look for it in your dashboard.

Select this, and in “Header,” paste the code mentioned above, then “Save.”

6. Alternatively, call an expert

We get it. Muddling around with code is a bit daunting, especially if you need to make changes to your theme’s functions.php file.

So if you’re unsure about making potentially harmful changes to your site, it’s best to call an expert.

Start by contacting your web host. They can help you make code edits and look deeper into issues such as jQuery errors.

However, even the most reputable web hosts take time to handle queries. Since time is of the essence, we recommend you contact a WordPress developer instead.

StateWP’s expert developers aim to respond and fix WordPress problems you raise within a day of you sending a request. All you need to do is head to Proto, our custom WordPress management dashboard, and submit a service request like so:

 jQuery Is Not Defined WordPress Error being submitted to Proto

You don’t even need to have followed this guide to the letter. If you just want an expert to review the jQuery problem, just contact us, and we can get you back up and running.

If you can’t access your dashboard, call us for an equally speedy fix.

Fix the jQuery Is Not Defined WordPress Error and Get Back Online

The longer you leave something like a jQuery is Not Defined WordPress error, the longer your visitors have to wait for your WordPress page to open back up.

Thankfully, with some code editing, the WordPress admin jQuery is not defined error is easier than you think to fix.

However, we fully understand that many people prefer to ask for help from developers to get WordPress errors straight – and that’s where we come in.

When you sign up as a StateWP partner, you can access 24/7 error support and WordPress site management. You’re never in the dark.


GIPHY

On the subject of fixing errors, while you’re here, we recommend you take a good look through our guide to some of the most common WordPress errors and how to solve them.

From there, check out our website hosting and maintenance guide and get ahead of any future problems.

x