Using this link, you will find helpful notes as to how to add a script to your WordPress website.
The main idea is to use inbuilt WordPress functions to load your scripts. This is done via the wp_enqueue_script
function. Following examples provided in the aforementioned link, you will be able to learn how to enqueue your scripts the safe and secure way!
NOTE: Don’t get confused with the different functions – wp_enqueue_style
is used for loading custom CSS stylesheets, NOT JavaScript code.
function load_your_scripts() {
wp_enqueue_style( 'style-name', get_stylesheet_uri() ); // Used for loading stylesheets
wp_enqueue_script( 'script-name', get_template_directory_uri() . '/WHEREVER/YOUR/FILE/IS/example.js', array(), '1.0.0', true ); // Used for loading scripts
}
add_action( 'wp_enqueue_scripts', 'load_your_scripts' );
Please let me know if you run in to any issues with your code and I will be sure to help you along the way 🙂