How to Move Jquery Scripts in Footer on WordPress

In this topic I will tell you how to move jQuery scripts from head into footer on WordPress. This improvement will give you performance because doing so will allow jQuery to be called after the page has been loaded so that this page will be opened faster. Google page speed will increase at the value you get at the speed. You can do this by adding the following code to the function.php file.

This code will be moved along with the wordpress jQuery, jQuery core and jQuery migrate files to the footer.

 

function move_enqueue_scripts() {
    wp_scripts()->add_data( 'jquery', 'group', 1 );
    wp_scripts()->add_data( 'jquery-core', 'group', 1 );
    wp_scripts()->add_data( 'jquery-migrate', 'group', 1 );
}
add_action( 'wp_enqueue_scripts', 'move_enqueue_scripts' );

Leave a Reply

Your email address will not be published. Required fields are marked *