jquery is not defined

The first birthday of your newly launched WordPress site can quickly become a miserable, cakeless affair. The site's performance is dreadful, with critical scripts failing and error messages trailing in the browser console. Promises of smooth sliders, interactive forms, and dynamic content are off-track. And in the developer tools, you are humiliated by a persistent console error, as a missing dependency guts the functionality of your theme and plugins. On the front end, your features weep and user experience plummets. The website has never looked weaker, all because of a single, common error: "jQuery is not defined."

How to Fix the "jQuery is not defined" Error in WordPress

This error is a classic sign of a script conflict, where a theme or plugin is trying to use the jQuery library before WordPress has loaded it. It's a technical hiccup, but one you can often resolve without deep coding knowledge. The key is to approach the problem methodically, starting with the simplest solutions before moving to more involved ones. Think of it like troubleshooting a car that won't start; you check the battery before rebuilding the engine.

Here is a step-by-step guide to get your site back on track:

  • Step 1: Identify the Culprit: The first action is to find what's causing the error. Deactivate all your plugins. If the error disappears, reactivate them one by one, checking your site after each activation, until the error returns. The last plugin activated is likely the cause. If the error persists with all plugins off, the issue is probably with your active WordPress theme.
  • Step 2: Check for Hard-Coded Scripts: Some older themes or custom code might include a direct link to jQuery from a CDN, which conflicts with WordPress's own version. Inspect your theme files, particularly the header.php and footer.php, and look for lines that start with <script src="...jquery.... If you find one that doesn't use WordPress's proper enqueue method, you may need to remove it or seek developer help.
  • Step 3: Use a Dedicated Plugin: For a quick and safe fix, consider using a plugin like "Enable jQuery Migrate Helper" or "jQuery Manager for WordPress." These tools can restore compatibility for older scripts that rely on deprecated jQuery code, often silencing the error immediately.
  • Step 4: Update Everything: An outdated WordPress core, theme, or plugin is a frequent source of script conflicts. Ensure your WordPress installation, all plugins, and your theme are updated to their latest versions. This simple maintenance step resolves a surprising number of website functionality issues.
  • Step 5: Enqueue jQuery Properly (Advanced): If you are comfortable with code, the correct fix is to ensure your theme or custom plugin properly enqueues jQuery using WordPress's wp_enqueue_script() function. This tells WordPress to load the library in the correct order. You can add this code to your theme's functions.php file or a site-specific plugin.

What does 'jQuery is not defined' mean?

This error message means that a piece of JavaScript code on your website is trying to use the jQuery library, but the browser cannot find it. jQuery is a popular JavaScript library that simplifies tasks like animations, event handling, and HTML document traversal. WordPress includes jQuery by default, but if a theme or plugin tries to call a jQuery function before the library is fully loaded, or if it loads a conflicting version, the browser throws this error and the dependent script fails to run.

How do I enable jQuery in WordPress?

WordPress comes with jQuery enabled by default, so you usually don't need to "enable" it. The core software and many plugins rely on it. The problem arises from how it's loaded. To ensure it's available, avoid manually adding jQuery via a <script> tag in your theme header. Instead, rely on WordPress's built-in system. If you are writing custom code, always use the proper wp_enqueue_script() function to declare jQuery as a dependency for your script. This guarantees it loads in the right order.

If you suspect jQuery has been improperly removed, you can check your theme's functions.php file for any code that uses wp_deregister_script('jquery'). Removing such a line would restore the default jQuery. For most users, the error is not about enabling jQuery but resolving conflicts that prevent it from loading correctly for specific scripts, which is why testing on a duplicate staging site is a safe practice before making live changes.

Why is jQuery not working in my browser?

If jQuery isn't working, it's almost always a site issue, not a browser setting. However, you can perform a quick browser check. First, open your browser's Developer Tools (usually F12) and go to the Console tab. If you see the "jQuery is not defined" error, the problem is with the website's code. Try a hard refresh (Ctrl+F5 or Cmd+Shift+R) to clear the cache. Also, ensure you don't have browser extensions, like aggressive script blockers, that might be interfering with jQuery loading on certain sites.

For site owners, the root cause is typically a conflict. A plugin might be deregistering WordPress's jQuery to load its own, but then failing. Your theme's custom JavaScript might have errors or incorrect dependencies. Sometimes, moving your site to a new host or changing your WordPress site's domain name can inadvertently break script paths if URLs aren't updated properly in the database, leading to missing resources.

How do I check jQuery version in WordPress?

You can check the jQuery version loaded on your WordPress site directly from the browser. Simply navigate to your website, open the Developer Tools (F12), and go to the Console tab. Type jQuery.fn.jquery and press Enter. The console will print the version number currently in use. Alternatively, you can view the page source (Ctrl+U) and search for "jquery.js" or "jquery.min.js" in the HTML; the URL often contains the version number.

Knowing the version is helpful for compatibility. Newer WordPress versions ship with recent jQuery releases. If a plugin requires an older version, it can cause conflicts. The table below shows common jQuery versions bundled with recent WordPress releases:

WordPress VersionBundled jQuery Version
6.6 and above3.7.1
6.0 to 6.53.6.0
5.8 to 5.93.6.0

If you need to load a different version for a specific purpose, you must do so carefully using the enqueue system to avoid conflicts with core and other plugins, a task where modifying your theme's functions.php file might be necessary.

Can I use JavaScript instead of jQuery in WordPress?

Absolutely. Modern JavaScript (often referred to as vanilla JS) can handle many tasks that jQuery was traditionally used for. Using vanilla JS can lead to faster page loads since you aren't loading an additional library. For simple interactions like toggling a menu or handling a click event, vanilla JS is often a leaner and more modern approach. Many newer WordPress themes and plugins are moving in this direction to improve performance.

However, jQuery's strength is its simplicity and cross-browser compatibility for more complex operations. A vast ecosystem of WordPress plugins still depends on it. If you decide to replace jQuery scripts, you must thoroughly test all site functionality. For custom development, you can choose the best tool for the job. Remember, if you remove jQuery entirely, you must ensure no core features, themes, or plugins break, which can be a complex process similar to managing technical SEO during a major platform migration.

How do I add a custom jQuery script to WordPress?

The correct way to add a custom jQuery script is by enqueuing it in your theme's functions.php file or a custom plugin. Use the wp_enqueue_script() function and explicitly set 'jquery' as a dependency. This tells WordPress to load your script only after jQuery is ready. Never just paste a <script> tag into your theme header, as this can

Table of Contents

WordPress Speed Optimization

Boost your site performance and improve user experience with our specialized speed optimization service.

Accelerate Your Site
WordPress Speed Optimization
Previous Article Next Article
Chat with me

Start a Conversation

Hi! Let's connect on your preferred platform.