admin管理员组文章数量:1287576
i am trying to use the jQuery-ui function: slider(): here's my code that i wrote inside the jQuery(document).ready...:
jQuery("#slider-wp").slider()
and in my functions.php file i wrote this code to call the jQuery library specific to slider():
function jquery_scripts(){
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-slider');
}
add_action( 'admin_enqueue_scripts', 'jquery_scripts');
when i loaded my page i recevied this error:
i tried to look into many ressources on the internet but without success.
here's the shortcode in my functions.php file where i want to add the slider:
function rangeSlider(){
ob_start();
include 'rangeSliderfct.php';
return ob_get_clean();
}
add_shortcode('tarifs_slider', 'rangeSlider');
and here's the included php file:
<input type="text" name="value">
<div id="slider-wp"></div>
thanks for the ideas...
i am trying to use the jQuery-ui function: slider(): here's my code that i wrote inside the jQuery(document).ready...:
jQuery("#slider-wp").slider()
and in my functions.php file i wrote this code to call the jQuery library specific to slider():
function jquery_scripts(){
wp_enqueue_script('jquery');
wp_enqueue_script('jquery-ui-slider');
}
add_action( 'admin_enqueue_scripts', 'jquery_scripts');
when i loaded my page i recevied this error:
i tried to look into many ressources on the internet but without success.
here's the shortcode in my functions.php file where i want to add the slider:
function rangeSlider(){
ob_start();
include 'rangeSliderfct.php';
return ob_get_clean();
}
add_shortcode('tarifs_slider', 'rangeSlider');
and here's the included php file:
<input type="text" name="value">
<div id="slider-wp"></div>
thanks for the ideas...
Share Improve this question edited Oct 13, 2021 at 7:26 OmarAc asked Oct 12, 2021 at 15:26 OmarAcOmarAc 31 silver badge5 bronze badges 4 |1 Answer
Reset to default 1The error message is clear; the function is not exist. It would help if you looked at your dependencies. You need jQuery Core, the jQuery UI library, and the jQuery Slider library. But no worries, you should use the dependency handling from WP API via wp_enqueue_script
and his internal handles to load in the correct order.
wp_register_script(
'your-jquery-slider',
plugin_dir_url( __FILE__ ) . './js/your-jquery-slider.js',
[
'jquery-ui-core',
'jquery-ui-slider',
]
);
wp_enqueue_script( 'your-jquery-slider' );
With these parameters, you make sure that the libraries are in place and right order. The handle jquery
is not necessary, because the WP API define jQuery as dependency for jquery-ui-core
, see this documentation table. The jQuery UI Effects are not included with the jquery-ui-core
handle, so you need the handle for the slider jquery-ui-slider
.
Note. Use the register function and then enqueue to give other plugins the chance to remove them, is clean, and have more control for everyone.
本文标签: javascriptUncaught TypeError jQuery()slider is not a function
版权声明:本文标题:javascript - Uncaught TypeError: jQuery(...).slider is not a function 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741273794a2369611.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
jQuery("#slider-wp").slider()
? does it have jQuery and the slider as dependencies? developer.wordpress/reference/functions/wp_enqueue_script – admcfajn Commented Oct 12, 2021 at 20:58