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

2 Answers 2

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.

4
  • 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, 2017 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, 2017 at 16:55
  • Yeah ... Little embarrassing but I just forgot to enqueue the CSS of the plugin ;-)
    – urban-a
    May 26, 2017 at 17:58
  • Ah bugger, those little silly bugs are the most Time consuming one's
    – xvilo
    May 26, 2017 at 21:37
0

I had a similar problem with my BxSlider Plugin which is now fixed (see excerpt below from my wcslider.php file) using your method, thank you very much.

function wcslider_scripts() {
    wp_enqueue_style('bxslider', WCSLIDER_PATH . '/css/jquery.bxslider.min.css');
    if(wp_script_is('jquery', 'enqueued')) {
        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('bxsliderjs', WCSLIDER_PATH . '/js/jquery.bxslider.min.js', array('jquery'), false, null);
    } else {
        wp_enqueue_script('jquery');
    }   wp_enqueue_script('bxsliderjs', WCSLIDER_PATH . '/js/jquery.bxslider.min.js', array('jquery'), false, null);
}
add_action('wp_enqueue_scripts', 'wcslider_scripts');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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