I'm developing a plugin and I'd like to use colorbox in my plugin . So I use wp_enqueue_script('jquery'); but it doesn't work . Then I search for it and add the following code and it is working now . But why should I deregister jquery ?

wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.8.1/jquery.min.js', false, '1.8.1');
  • 8
    You should not deregister jQuery. If your script doesn't work, debug the script, don't just try some random code snippets.
    – fuxia
    Nov 12 '16 at 8:27
  • It likely doesn't work because jQuery is in no conflict mode and you need to use jQuery(...) rather than $(...), or use an appropriate wrapper
    – Tom J Nowell
    Nov 13 '16 at 17:06

Linking jquery code twice conflicts the functions as they are present twice. So deregistering helps you but it is not good choice. You should go through jQuery no conflict thing. And you should register your jquery version with different name, so that it does not break wordpress.

Ref- jQuery Forum and Documentation


Building off what Vishal & toscho wrote:

You should avoid deregistering WordPress's version of jQuery. What those lines do is tell WP that you do not want to use their version, and that you want to use a different version of jQuery (version 1.8.1 in your example). Depending on your version of colorbox, the reason it might work now is because it wasn't compatible with the latest version of jQuery included in WP core.

So the best solution would be to find a jQuery plugin that works with the latest version of jQuery.

  • I think most of the plugin go for 'no conflict' thing and hence support multiple versions. Nov 14 '16 at 7:43
  • The OP indicated that they tried wp_enqueue_script('jquery'); first and it didn't work. They didn't say they were using two versions of jQuery, just that the WP one didn't work. If it was related to not using no conflict mode, wouldn't it still not work?
    – Megan
    Nov 14 '16 at 13:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.