The best way to avoid asset conflicts is to register the files correctly. For this you must use wp_enqueue_script
A good way to do this is to put it as part of a function in your functions.php file, for example,
- create function
- insert
wp_register_script into function - then insert
wp_enqeue_script into the function - use add_action () to initialize the queue process.
so -
function load_scripts() { wp_register_script( 'script-name', get_template_directory_uri() . '/js/script.js', array( 'scriptyouwillwaittobeloaded' ) ); wp_enqueue_script( 'script-name' ); } add_action('wp_enqueue_scripts', 'load_scripts');
In this example, the load_scripts() function will then be called in the header.php file. Take a look at wp_register_script for a better understanding of the arguments for this, but in a summary -
first argument: this is the name you want to use as a reference to this script
second argument: the actual link to the script
Third argument: this is the script you want to load before this script (the script you want to load before this script)
and for wp_enqueue_script, the argument is just a reference to the name (the first argument is wp_register_script)
arguments to the add_action function:
first argument: the function that you "connect" to
second argument: the function you created will be "connected"
To note, you can load as many scripts as you want in this function, this is just an example of loading a single script.
source share