Adding Multiple Javascript files to WordPress functions.php

I have managed to add one js file to the WP functions.php and this works fine. How do I add another? e.g add classie.js to the add_my_script function? I tried to duplicate the get_template_directory_uri() but this didn’t work – I feel as though the answer is staring me in the face!

add_action( 'wp_enqueue_scripts', 'add_my_script' );
function add_my_script() {
    wp_enqueue_script(
        'slicknav',// name your script so that you can attach other scripts and de-register, etc.
        get_template_directory_uri() . '/js/jquery.slicknav.min.js', // this is the location of your script file
        array('jquery') // this array lists the scripts upon which your script depends
    );
}

Related posts

Leave a Reply

1 comment

  1. You need to call the wp_enqueue_script twice:

    add_action( 'wp_enqueue_scripts', 'add_my_script' );
    function add_my_script() {
        wp_enqueue_script(
            'slicknav',
             get_template_directory_uri() . '/js/jquery.slicknav.min.js', 
             array('jquery') 
        );
        wp_enqueue_script(
            'classie',
             get_template_directory_uri() . '/js/classie.js', 
             array('jquery') 
        );
    }