I have used the below for many years to move jQuery to the footer.
JavaScript
x
7
1
// Move jQuery to footer
2
if( ! is_admin() ) {
3
wp_deregister_script( 'jquery' );
4
wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true );
5
wp_enqueue_script( 'jquery' );
6
}
7
But instead of loading the version shipped with WP (or ClassicPress too) I will download the latest version here https://releases.jquery.com/jquery/ to my theme folder.
So how do I now change the wp_register_script above to call a local version like ‘assets/js/jquery-3.6.1.js’?
Haven’t been able to find any solutions to load jQuery from my theme, only from Google etc which then creates problems for performance.
Thanks in advance.
Advertisement
Answer
JavaScript
1
6
1
if( ! is_admin() ) {
2
wp_deregister_script( 'jquery' );
3
wp_register_script( 'jquery', get_template_directory_uri() . '/assets/js/jquery-3.6.1.js', false, NULL, true );
4
wp_enqueue_script( 'jquery' );
5
}
6