Question

For an old Wordpress Plugin I need an older jQuery version.

So I thought I could deregister the preregistered jQuery from Wordpress and register a Library from Google CDN.

In the functions.php file I added these lines:

add_action( 'admin_enqueue_scripts', 'new_jquery_enque_func' );
function new_jquery_enque_func()
{
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.3/jquery.min.js', false);
    wp_enqueue_script('jquery');
}

When I reload the WP-Admin Page I get many of these Errors in several Files:

Uncaught ReferenceError: jQuery is not defined

What can I do to get this to work right?

Was it helpful?

Solution

You're not supposed to use another jQuery library. The jQuery library in WordPress is loaded in No Conflict mode to prevent issues with other libraries you might be using.

So, by default you should use jQuery instead of $. WordPress plugins also use jQuery in their code. Unregistering WordPress jQuery will cause the error:

Uncaught ReferenceError: jQuery is not defined

If you still want to use the $ inside your jQuery code, you can use noConflict Wrappers like:

jQuery(document).ready(function($) {
  // use $() inside!
});

The WordPress dashboard relies on the inbuilt jQuery version. If you really want to change jQuery, you can change it only on your theme using something like:

if( ! is_admin() ){
  add_action( 'admin_enqueue_scripts', 'new_jquery_enque_func' );
  function new_jquery_enque_func()
  {
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js', false);
    wp_enqueue_script('jquery');
  }
}

I might also add that jQuery 1.7.3 does not exist. jQuery 1.7.2 exists though, unless you confused with jQuery UI 1.7.3

OTHER TIPS

Your reference URL doesn't seem to be working..

It might be remove from the server, so better try latest.

Check

It has an error

Find some other URL or migrate to newer version 1.9.1 .

New Version

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top