简体   繁体   中英

Wordpress Plugin Error - jQuery is not defined

Im using a WP plugin wich enqueues a js file. Today i saw a the following error in the console

jquery is not defined...

After deactivating the plugin and activating it again the error is gone. Usually “jQuery is not defined” is a sign jQuery is being called incorrectly. I cheked the code and cant find any error. Any idea how to avoid this kind of error or is there any error in the following code?

function bb_qv_enqueue_scripts(){
wp_enqueue_script('bb-qv-js',plugins_url('/assets/js/bb-qv-js.js',__FILE__),array('jquery'),'1.7',true);
wp_localize_script('bb-qv-js','bb_qv_localize',array(
    'adminurl' => admin_url().'admin-ajax.php'
    ));
}
add_action('wp_enqueue_scripts','bb_qv_enqueue_scripts');

The error seems to be on the jQuery plugin since you are already specifying through wp_enqueue_script that the file requires jquery. This could be many things, maybe it's conflicting with some other library.

Try to declare a new alias for jQuery at the beginning of your file and then replace all jQuery or $ with the new alias. Something like this:

var newAlias = jQuery.noConflict();
newAlias(document).ready(function()...

Hope it can help!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM