admin管理员组文章数量:1302319
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 ) 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
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/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
Share Improve this question asked May 26, 2017 at 8:22 urban-aurban-a 31 silver badge3 bronze badges2 Answers
Reset to default 0You 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/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.
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/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');
本文标签: wp enqueue scriptjQuery Plugin Uncaught TypeError jQuery()slider is not a function
版权声明:本文标题:wp enqueue script - jQuery Plugin Uncaught TypeError: jQuery(...).slider is not a function 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741711937a2393895.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论