
By default, WordPress loads the jQuery javascript framework at the top of your files. Here’s a snippet to force WP to load jQuery in the theme footer.

By default, WordPress loads the jQuery javascript framework at the top of your files. Here’s a snippet to force WP to load jQuery in the theme footer.
Paste the following code in your functions.php file, save it, and you're done.
function ds_print_jquery_in_footer( &$scripts) {
if ( ! is_admin() )
$scripts->add_data( 'jquery', 'group', 1 );
}
add_action( 'wp_default_scripts', 'ds_print_jquery_in_footer' );
Credit: Dominik Schilling.
5 Responses
The correct way is using`wp_enqueue_scripts’ hook where wp_enqueue_script function has a parameter for footer (boolean header or not).
Will you tell what is the advantage when loading this jquery in footer ?
thanks in advance,
An alternative approach would be to disable the jQuery bundled with WordPress using the wp_deregister_script function and let Google host it for you:
ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js
Hi, You can add this true to the end of the wp_register_script
if( !is_admin()){
wp_deregister_script(‘jquery’);
wp_register_script(‘jquery’, (“http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js”), false, ’1.3.2′, true);
wp_enqueue_script(‘jquery’);
}
I think it is already been defined in the wp_enqueue_script where we want to load our javascripts files.
Trackbacks: