Moving jQuery to the footer without using de-register in WordPress

You should use the param $scripts of the hook wp_default_scripts. In this hook was en-queued all default scripts, also jQuery and you can change his data, like the group for load in footer.

add_action( 'wp_default_scripts', '_print_jquery_in_footer' );
function _print_jquery_in_footer( $scripts ) {

    if ( ! is_admin() )
        $scripts->add_data( 'jquery', 'group', 1 );
}

Also in the newer code style via anonymous function, like your question example; possible since php 5.3:

add_action(
    'wp_default_scripts',
    function( $scripts ) {
        if ( ! is_admin() )
            $scripts->add_data( 'jquery', 'group', 1 );
    }
);

Edit: This will only work with WordPress versions lower than 3.9!

Leave a Comment