I wanted to move jquery to the site’s footer, but that doesn’t work. I’ve tried it with the following code.
As you can see, I have a couple of another scripts and they load correctly on the footer. Only jquery won’t work.
//This adds our JavaScript Files
function wel_adding_scripts() {
wp_deregister_script('jquery');
wp_register_script('jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js', '', '2.1.1', true);
wp_enqueue_script( 'jquery');
wp_register_script('jquery.mixitup', get_template_directory_uri() . 'js/jquery.mixitup.min.js','','1.1', true);
wp_enqueue_script('jquery.mixitup');
wp_register_script('headroom', get_template_directory_uri() . 'js/headroom.min.js','','1.1', true);
wp_enqueue_script('headroom');
}
add_action( 'wp_enqueue_scripts', 'wel_adding_scripts' );
4 Answers
Note that if any script in the header at all needs jQuery then it will bump it to header, regardless if it’s changed to be enqueued for footer.
So while changing it to be queued for footer makes sense it rarely works out when a lot of script stuff is going on.