Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question
4  
The codex is your friend: codex.wordpress.org/Function_Reference/… –  vancoder Aug 6 '13 at 21:34
    
Thanks a lot. I missed that. +10 if I could. –  Greeso Aug 6 '13 at 21:38
add comment

1 Answer

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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