How can I add my script files to the very top in the wp_head?
From this guide, using the code below will always add my new script file to the very bottom:
add_action('wp_head','hook_javascript');
function hook_javascript() {
$output="<script> alert('Page is loading...'); </script>";
echo $output;
}
Any ideas how I can move my new script files to the top?
Use the
$priority
parameter of theadd_action()
function.So, choose a very low number and as long as no other plugin/theme uses an even lower number your line will be added at the top.
By default, this will put it in the header. If you change your mind in the future (and you should), you can pass
true
as fifth parameter ofwp_enqueue_script
and it will be placed at the bottom. Refer to the documentation for more info on params.