How to Move jQuery to Footer in WordPress

How to Move jQuery to Footer in WordPress

Loading jQuery in your WordPress website's footer can improve page load times and overall site performance. By default, WordPress loads jQuery in the header, which can delay the rendering of your page. Add the below code to the "functions.php" file of your theme. It will move "jQuery", "jQuery Core", and "jQuery Migrate" loading to the footer of your WordPress site.

function themesdna_move_jquery_to_footer() {
    if (!is_admin()) {
        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', 'themesdna_move_jquery_to_footer');

The above code uses the "wp_scripts()" function to access the global scripts object in WordPress and then uses the "add_data" method to set the "group" property of the "jquery", "jquery-core", and "jquery-migrate" scripts to "1". In WordPress, setting the "group" to "1" indicates that the script should be loaded in the footer. By default, scripts are loaded in the header unless specified otherwise.

Our WordPress Themes

Below are some of our premium WordPress themes. View all our free and premium WordPress themes →
NeatBlog PRO WordPress Theme

NeatBlog PRO

NeatBlog PRO WordPress Theme is the advanced, feature-rich version of the NeatBlog Free WordPress Theme. NeatBlog PRO version has color...

$25.00
ElegantWP PRO WordPress Theme

ElegantWP PRO

If you like ElegantWP free WordPress Theme, you will love the premium version. ElegantWP PRO is very user friendly, feature-rich,...

$25.00
CleanWP PRO WordPress Theme

CleanWP PRO

If you like CleanWP free WordPress Theme, you will love the CleanWP PRO version. The premium version of CleanWP WordPress...

$25.00
GridBone PRO WordPress Theme

GridBone PRO

$25.00
ListMode PRO WordPress Theme

ListMode PRO

$25.00
MaxWP PRO WordPress Theme

MaxWP PRO

If you like MaxWP free WordPress Theme, you will love the premium version. MaxWP PRO is feature-rich, easy to use,...

$25.00
GridMini PRO WordPress Theme

GridMini PRO

Do you like the free version of the GridMini WordPress theme? But what if you need more features and options?...

$25.00
Clean Grid PRO WordPress Theme

Clean Grid PRO

If you like Clean Grid free WordPress Theme, you will love the premium version. Clean Grid PRO is an elegant,...

$25.00

Can't you choose a single theme? Purchase All Themes for $75.

Save money with our low, one-time price for access to all of our 56 WordPress themes.