Registering jQuery kills admin functions

I recently added the following into my theme’s functions.php, in order to load jQuery from the CDN:

function my_init_method() {
    wp_deregister_script('jquery');
    wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js');
}

add_action('init', 'my_init_method');

However, this causes problems with the admin screens, notably the WYSIWYG editor which then refuses to allow HTML mode (via the tab). I get an error:

Read More
jQuery is not defined

from the wp-admin/load_scripts.php file. What am I doing wrong?

Related posts

Leave a Reply

1 comment

  1. jQuery is not defined

    This is because the Google CDN Jquery is not in no-conflict mode. Use the following to make sure the included WordPress no-conflict jquery is used in admin.

    if( !is_admin()){
       wp_deregister_script('jquery'); 
       wp_register_script('jquery', ("http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"), false, '1.4.2'); 
       wp_enqueue_script('jquery');
    }