1

I'm making a custom implementation of JQuery Colorbox in a Wordpress plugin. However, it's not working with my default Wordpress installation. After tinkering a bit, it comes down to the inclusion of the JQuery library.

Neither of these lines work:

<script src='http://xpisobsolete.com/wp-includes/js/jquery/jquery.js?ver=1.10.2'></script>

<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

But either one of these do:

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>

I've tested that JQuery works with all of the above by using:

if (typeof jQuery != 'undefined') {

    alert("jQuery library is loaded!");

}else{

    alert("jQuery library is not found!");

}

It passes on all four of the script links I've tried. If I change that one line on Jack's demo page, it breaks as well. Is this a colorbox issue? http://www.jacklmoore.com/colorbox/example1/

Could you guys help me see what I'm missing here? I'm stumped.

  • I'm able to bypass the issue by using wp_deregister_script('jquery') and then wp_register_script to update the URL to JQuery that works. But I'd rather not have to overwrite JQuery to make this simple plugin work. – Jonathan Potter Feb 20 '14 at 21:01
  • 1
    Please read into the dependency API in detail in Codex. This will solve your answer. We also have some questions asking to replace the default version WP ships. Please use the search, then improve your question or mark it as duplicate. – kaiser Feb 20 '14 at 22:04
  • Most likely, your code uses $, which doesn't work with the version of jQuery that comes with WordPress because its in no conflict mode. – Manny Fleurmond Feb 21 '14 at 4:14
0

Try placing your code in this

(function($) {
    // Inside of this function, $() will work as an alias for jQuery()
    // and other libraries also using $ will not be accessible under this shortcut
})(jQuery);

I'm suspecting your code uses $, which is normally an alias for jQuery but doesn't work globally because WP's version of jQuery is in no conflict mode. $ will work if the code is placed in an enclosure such as the one above.

  • 1
    That solved the problem precisely. I'll be doing some reading on no conflict mode now. Sure appreciate it! – Jonathan Potter Feb 21 '14 at 5:19
  • No problem. Glad I was able to help. Look up the WordPress Codex entry of wp_enqueue_script for more info on no conflict mode – Manny Fleurmond Feb 21 '14 at 5:20

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.