jQuery Is Not Defined WordPress Solution
Are you getting “Uncaught ReferenceError: jQuery is not defined” error in WordPress ? It is one of the common WordPress jQuery error. “jQuery is not defined” error needs some debugging and can be fixed.
What causes “Uncaught ReferenceError: jQuery Is Not Defined” error in WordPress ?
There might be multiple reasons why are you getting error related to jQuery in your WordPress theme or plugin. Below are some of the common reasons
- jQuery file loading issue
- JavaScript/jQuery code sequencing
Solution to “Uncaught ReferenceError: jQuery Is Not Defined” error in WordPress ?
If you are loading jQuery from CDN or some other domain then don’t forget to check whether the jQuery file is loaded or not. Sometimes there might be some security permissions specified in configuration of your web server. Please check if you have given permission to load resources from third party websites.
Check if your code from theme or plugin is loading prior to jQuery plugin loading. Sometimes the plugin code gets executed before loading the jQuery, so make sure that have jQuery loaded before doing any processing.
So if you have a plugin where you are using WordPress wp_enqueue_script function to load your JavaScript file. Then don’t forget to specify dependency to be available before loading your JavaScript file. You can add your JS file using following syntax and add dependency using “array(‘jquery’)” as a parameter.
wp_enqueue_script("yourjsfile","jspath",array('jquery'), true);
Also do not forget to write your code inside $(document).ready function to avoid any pre execution.
Leave a Reply