0

I understand that in order to use a JavaScript library in WordPress, such as jQuery, we have to use the following code to prevent conflicts:

function my_scripts_method() {
    wp_enqueue_script( 'jquery' );
}

add_action('wp_enqueue_scripts', 'my_scripts_method' ); 

But how do I go about using a library that is not in the list of defined WordPress libraries. I am in particular interested in using the library at pikachoose.com which depends on jQuery, and must be intialized after jQuery. How do I go about that?

1

1 Answer 1

1

This is how you should do this:

function my_scripts_method() {
    wp_enqueue_script(
        'pikachoose',  // this is your custom name for this JS lib
        get_stylesheet_directory_uri() . '/js/pikachoose/jquery.pikachoose.min.js',  // this is the url address of it's file (let's say you put it in your theme directory under /js/pikachoose/ directory
        array( 'jquery' )  // it depends on jquery
    );
}
add_action( 'wp_enqueue_scripts', 'my_scripts_method' );

You can find full reference of wp_enqueue_script here: http://codex.wordpress.org/Function_Reference/wp_enqueue_script

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.