How to Fix "WordPress JQuery is Not Defined" Error?
Today, approximately 80% of websites run on jQuery, if your wordpress website is one of them, you might encounter the βUncaught ReferenceError: jQuery is not definedβ error at some point. This error message indicates that your website canβt call a function from the jQuery JavaScript library. This may cause one or multiple website elements to stop running. Luckily there are multiple methods to fix this common issue.Β
In this comprehensive tutorial, we will go through the methods to do so for WordPress users.
What Is the βjQuery Is Not Definedβ Error in Wordpress?
βjQuery is not definedβ error in wordpress is a common error that occurs when a website calls for a jQuery function before the library loads properly but the jQuery.com JavaScript library is unavailable or isnβt functioning correctly. It is caused possibly due to conflicting plugins, a corrupted jQuery file, a blocked CDN, or your JavaScript code loads incorrectly.β
It can crash your wordpress website because of corrupted WordPressβs plugins or jQuery files, hosting issues, or CDN problems. Simply, your website canβt communicate with its library because of broken or conflicting code.
Key Reasons of the βjQuery Is Not Defined Errorβ
This error in WordPress is pretty common. Here are some key reasons of this issue:
Corrupted WP Themes or Plugins
Errors with JavaScript or jQuery file
JavaScript Running Incorrectly
Blocked CDN-hosted jQuery
Poor Performing Host
What are Negative Impacts of this Error on Website?
A "jQuery is Not Defined" error in WordPress can impose some negative effects on your website's functionality and user experience:
Broken Functionality of Site
Affects User Experience
Increased Bounce Rate
Negative Impact on SEOΒ
Loss of Revenue
Loss of Brand Value
Damage Site AuthorityΒ
How To Fix the βUncaught Reference Error: jQuery Is Not Definedβ WordPress Error
Before starting fixing the error, create a site backup if something goes wrong. Setting automated backups is recommended. Beyond this, we also recommend running any changes you make to your site through a staging environment. Donβt make any changes to your live website while troubleshooting. Finally, ensure you have access to an FTP or File Transfer Protocol client. 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 should just prefer expert support, you can skip ahead and contact Supportfly.
1. Check jQuery is Included
Firstly, check that your website 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.
Now find the code that makes up your page. From here, press CTRL+F on Windows or CMD+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 appear, check the Network tab of your browserβs dev tools to see if you notice any jQuery takes being loaded. In your root folder, typically in βpublic_html,β look for a folder called βwp-includesβ.
Open βwp-includesβ and then open the file named βscript-loader.php.β Now in the source code, search for a line that starts with βwp_enqueue_script.β and after the word βscriptβ in this phrase paste the below given bold lines-
wp_enqueue_script( βtt-mobile-menuβ, get_template_directory_uri() .
β/js/mobile-menu.jsβ, array(βjqueryβ), β1.0β, true );
In WordPress you can do this all using Plugin. You can add code to your site using this plugin without editing text files.
Go back to your website and see if the problem is resolved.
2. Check jQuery is loading correctly
Now, we need to check, jQuery file is loading as expected. To start, right-click anywhere on your web page and select βView Page Source.β and search for queries in the code that start with β<script src=β and include βjqueryβ in the same lines.
If you see lines in the code matching this description, itβs likely loading correctly. Now move to the next step if you canβt see any matches.
3. Add a snippet to wp-config.php File
Still, if the above given ways don't work, you need to edit your websiteβs configurations. Look for the wp-config.php file in your root folder.
Right-click on the webpage anywhere 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.
Now, find 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 will help your website to recognize that jQuery is cavailable. Save the file and try to reload your website.
4. Set up Google-hosted jQuery with an alternate fallback
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.
5. Manually add the jQuery Library to header.php
If step four didnβt resolve the error, 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 marked folder βwp-contentβ in your root folder βpublic_htmlβ, then go to the β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 try to re-access your site.Β
Conclusion
In conclusion, jQuery is one of the most common errors occurring in wordpress sites. In this tutorial we have explained about what βjQuery is not definedβ is, some of the key reasons for this error and some methods of fixing this error that will definitely help you to fix this error. Nevertheless you are not able to resolve the "jQuery is Not Defined" error in WordPress. It can extend the time your visitors have to wait for your WordPress page to load. Fortunately, with some code editing, fixing the WordPress admin jQuery error is simpler than you might expect.
Muddling around with code may beΒ 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 contact a wordpress expert.Β
Contact Supportfly and hire an expert team for WordPress Management services to boost your website performance. We provide Premier Wordpress Management services to run your website on WordPress successfully.













