How to properly enqueue jQuery knob on WordPress without conflict?

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' );

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

If 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 );


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x