javascriptjquerywordpressenqueue

Include jQuery Core in Theme Folder and Enqueue to Footer


I have used the below for many years to move jQuery to the footer.

// Move jQuery to footer
    if( ! is_admin() ) {
        wp_deregister_script( 'jquery' );
        wp_register_script( 'jquery', includes_url( '/js/jquery/jquery.js' ), false, NULL, true );
        wp_enqueue_script( 'jquery' );
    }

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.


Solution

  • if( ! is_admin() ) {
            wp_deregister_script( 'jquery' );
            wp_register_script( 'jquery', get_template_directory_uri() . '/assets/js/jquery-3.6.1.js', false, NULL, true );
            wp_enqueue_script( 'jquery' );
        }