Everyone knows it is mostly unrecommended to hard-code direct calls for js scripts on your templates header. There are many reasons for that, most of them relating to different scripts and api’s incompatibility, that eventually may cause conflicts and wrong behavior of your page. Instead WordPress suggests two core functions to do the same trick:
Usage and differences in short:
The main idea is to always see to that the script is not in conflict with other scripts on the page, and on the other hand, that it has all the required dependencies to work properly. The enqueue_script function should take care of that.
<?php wp_enqueue_script( $handle, $src, $deps, $ver, $in_footer ); ?>
$handle – a string representing the label for this script for further reference.
$dep (array – optional) an array of all the dependencies that this script should rely on, each dependency is referred to by the label it was enqueued with
$ver (string -optional) – the script version number
$in_footer (boolean – optional) – should this script be called on the footer.
The main goal of this function is to set a script and determine it’s dependencies, so in case these dependencies are not registered – an exception can be handled by WordPress.
Registering a new script
<?php wp_register_script( $handle, $src, $deps, $ver, $in_footer ); ?>
Note that this functions accepts the same parameters as the wp_enqueue_script function.
For further reading on WordPress api codex, click here: http://codex.wordpress.org/Function_Reference/wp_register_script