Add JavaScript to a Theme

If you want to add a JavaScript file to a theme, you can use the snippet below:

function wpkb_add_my_js() {
    wp_enqueue_script( 'my-js', get_stylesheet_directory_uri() . '/js/script.js', array(), '1.0.0', true );
}

add_action( 'wp_enqueue_scripts', 'wpkb_add_my_js' );