I'm building a plugin and I want to use jQuery Knob but it seems like using this method:
plugins_url( '/assets/js/jquery.knob.min.js, . . . . .
Have conflicts with other plugins?
How to convert it like this?
wp_enqueue_script( 'jquery-ui-widget' );
wp_enqueue_script( 'jquery-ui-mouse' );
wp_enqueue_script( 'jquery-ui-accordion' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'jquery-ui-slider' );
I'm building a plugin and I want to use jQuery Knob but it seems like using this method:
plugins_url( '/assets/js/jquery.knob.min.js, . . . . .
Have conflicts with other plugins?
How to convert it like this?
wp_enqueue_script( 'jquery-ui-widget' );
wp_enqueue_script( 'jquery-ui-mouse' );
wp_enqueue_script( 'jquery-ui-accordion' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
wp_enqueue_script( 'jquery-ui-slider' );
Share
Improve this question
asked Oct 19, 2020 at 7:53
MarlonMarlon
318 bronze badges
1
- What are the conflicts specifically please? Just a missing jQuery declaration because o the load order, or is that not finding the file, or something else? – Rup Commented Oct 19, 2020 at 8:50
1 Answer
Reset to default 0If you want to just enqueue a script by name then you have to register it first with wp_register_script:
wp_register_script( 'jquery-knob',
plugins_url( 'assets/js/jquery.knob.min.js', __FILE__ ),
array( 'jquery' ), '1.2.11' );
:
wp_enqueue_script( 'jquery-knob' );
However that's only really useful when you're registering a script to be available as a dependency for other scripts, which I don't think you are here. Instead it's easier to register and enqueue it in one go, which you should do from a wp_enqueue_scripts hook:
function enqueue_jquery_knob() {
wp_enqueue_script( 'jquery-knob',
plugins_url( 'assets/js/jquery.knob.min.js', __FILE__ ),
array( 'jquery' ), '1.2.11' );
}
add_action( 'wp_enqueue_scripts', 'enqueue_jquery_knob', 10, 0 );