0

I made a plugin for my webpage. It works as a standalone HTML file fine. But when I use it as wp plugin a jQuery Plugin I need (Bootstrap Slider https://github.com/seiyria/bootstrap-slider) throws this error above.

I included jquery and this boostrap-slider plugin like that:

wp_enqueue_script( 'child_jquery','cdn URl');
wp_enqueue_script('bootstrap-slider',  'CDN Url');

And call the plugin in my code so:

jQuery("#m1,#m2,#m3,#m4,#m5,#m6,#m7,#m8,#m9,#m10,#m11,#m12").slider({
    reversed : true,
    tooltip: 'show'
});

This call is within a document ready function:

jQuery(document).ready(function(){

My suspicion, after the plugin is loaded a further jquery is enqued. So in the source code I have (simplified):

jquery.js
bootstrap-slider.js
jquery.js (an old one from wp)

I tried to deregister it and right after that enqueue it again. But if I do that the plugin still doesn't work and another plugin throws this error.

Any ideas?

Thanks in advance

0

You can try this code:

add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
 function my_jquery_enqueue() {
   wp_deregister_script('jquery');
   wp_register_script('jquery', "//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js", false, null);
   wp_enqueue_script('jquery');
   wp_enqueue_script('bootstrap-slider',  'CDN Url', array('jquery'), false, null);
}

What I am doing is deregistering the WP jQuery script. Then I'll add a new jQuery script with the CDN. I will enqueue this script and then enqueue your bootstrap slider script with jquery as a dependency. This means jQuery will be loaded BEFORE Bootstrap Slider.

Let me know if this works for you.

  • Thank you very much! I already found the deregister and register but never with the dependency factor. My slider still not works but a least, no error anymore :) I can work from there. Thanks! – urban-a May 26 '17 at 12:11
  • Probably you need to also initialize the slider with some other Javascript. You need to use this after the jquery en bootstraplider js files. You can enqueue another script file with that piece of code and require both jquery and bootstrap-slider with array('jquery', bootstrap-slider ). – xvilo May 26 '17 at 16:55
  • Yeah ... Little embarrassing but I just forgot to enqueue the CSS of the plugin ;-) – urban-a May 26 '17 at 17:58
  • Ah bugger, those little silly bugs are the most Time consuming one's – xvilo May 26 '17 at 21:37

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.