Adding dependencies to script enqueing

Try this. You have to call wp_enqueue_script at the appropriate time, so that it can queue your scripts until the dependencies you specify are called –

add_action('wp_enqueue_scripts', 'enqueue_my_scripts');
function enqueue_my_scripts(){

    wp_enqueue_script(
        'jscripts',
        get_stylesheet_directory_uri() . "/scripts/jscripts.js",
        array('jquery-ui-datepicker'));

    echo wp_script_is('jquery-ui-datepicker', 'queue')
        ? '<br>' . '[jquery-ui-datepicker] Script is enqueued' . '<br>'
        : '<br>' . '[jquery-ui-datepicker] Script not enqueued' . '<br>';

}

This is assuming your scripts are to be called on the front end. Substitute wp_enqueue_scripts with admin_enqueue_scripts if it is for the admin area (for a plugin, for example).

Leave a Comment