In WordPress used wp_enqueue_scripts() to register your scripts.
For more information click here
add_action('wp_enqueue_scripts', 'my_enqueue_scripts');
function my_enqueue_scripts() {
wp_register_script( 'alliance_script', get_template_directory_uri() . '/js/script.js');
wp_enqueue_script( 'alliance_script' );
}
wp_register_script vs. wp_enqueue_script
wp_register_script()
function makes your scripts available for use while wp_enqueue_script()
functions loads the script to the theme/plugin.
- You can register without enqueuing. But to load the script on the page, you need to enqueue. If you register the script, you can then enqueue it by its handle alone. If you don’t register it ahead of time, you will need to provide the full parameters in the enqueue function.
- You can skip the register function for the scripts that you are going to enqueue right away. Also, you don’t need to register scripts which are included in WordPress.