Move jQuery to the bottom of the page whilst keeping the WordPress jQuery

I wish to move jQuery to the bottom of the page on my theme, to speed up loading times.

Previously I was doing this by replacing it with Google’s CDN version but I have been told that is a bad thing to do.

Read More

How can I deregister and re-register the WordPress jQuery script and move it to the bottom without causing any problems?

Related posts

Leave a Reply

1 comment

  1. You can change it by calling add_data method of $wp_scripts object. This object holds all scripts and information how to render it. To force rendering script in the footer you can do it like this:

    add_action( 'wp_enqueue_scripts', 'wpse8170_enqueue_scripts' );
    function wpse8170_enqueue_scripts() {
        $GLOBALS["wp_scripts"]->add_data( 'jquery', 'group', 1 );
    }
    

    P.S.: I haven’t tested it, but suppose it has to work.