0

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

0

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 );
2
  • There is still a conflict when I did this.
    – Marlon
    Commented Oct 29, 2020 at 9:18
  • OK. Can you give us more details of the conflict please? I guess you're seeing errors in the browser debug tools JavaScript console? Can you edit them into the question? Can you also please check the Network tab to see if any of the scripts failed to load?
    – Rup
    Commented Oct 29, 2020 at 9:46

Your Answer

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

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