Accoriding to the WP Reference for wp_enqueue_scripts
wp_enqueue_script( string $handle, string $src = false, array $deps = array(), string|bool|null $ver = false, bool $in_footer = false )
The last parameter is responsible for where the script will be loaded.
There are some snags which can change his behaviour !
Try to find and comment/remove this lines from your function.php file
remove_action('wp_head', 'wp_print_scripts');
remove_action('wp_head', 'wp_print_head_scripts', 9);
remove_action('wp_head', 'wp_enqueue_scripts', 1);
add_action('wp_footer', 'wp_print_scripts', 5);
add_action('wp_footer', 'wp_enqueue_scripts', 5);
add_action('wp_footer', 'wp_print_head_scripts', 5);
The purpose of this six actions is to automatically move JavaScript code to page footer making the last parameter from wp_enqueue_scripts unuseful!
If this actions can not be removed, then you can change the priorities of them. From 5 to 9999 per example. Play with the priorities to find the right one for you.
You also need to check if the are some dependencies specified in the $deps array.Witch gone force the script to be loaded after resolving them.
Don't try any dirty hacks, it is a bad practice
Happy coding
jQuery("body").css("background-color","red");
executed from within a shortcode in the body, I can't do it. Let's say my shortcode is[body color=red]
but jquery isn't loaded till the footer, then my code won't work.wp_localize_script
, or output the script inline in the footer.