Select Page

If you want to speed up your WordPress website, you might want to move jQuery to the footer of your website. If it’s right before the closing </body> tag, then the browser will load it after all the content has been loaded. This will make sure your users see the content before the jQuery file has been loaded.

If the jQuery file is loaded in the <head>, then your users will see a blank page until that file is loaded.

To move jQuery to the bottom of the HTML, place this code in your theme’s functions.php file:

// This function will move the jQuery script to the footer of your page.
function move_jquery_to_footer() {
	// First, deregister the jQuery file.
    wp_deregister_script( 'jquery' );
	// Then register the file again.
	// The last argument of wp_register_script will load this script in the footer.
    wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true );
	// Now, enqueue the script again.
    wp_enqueue_script( 'jquery' );
add_action( 'wp_enqueue_scripts', 'move_jquery_to_footer' );

The above code first deregisters the jQuery script. And then registers it again but at the bottom of the page. And then the code enqueues the script again.