This code snippet removes JavaScript (including jQuery) from your WordPress website’s header and moves it to the footer, optimizing your page load speeds. Just paste it into your theme’s functions.php.
if(!is_admin()){ remove_action('wp_head', 'wp_print_scripts'); remove_action('wp_head', 'wp_print_head_scripts', 9); remove_action('wp_head', 'wp_enqueue_scripts', 1); add_action('wp_footer', 'wp_print_scripts', 5); add_action('wp_footer', 'wp_enqueue_scripts', 5); add_action('wp_footer', 'wp_print_head_scripts', 5); 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'); }
See original article on moving JavaScript to WordPress footer.
Tomasz says
What about non-registered WordPress scripts and styles injected non-correctly by 3rd party plugins? More advanced solution here: http://tomasz-dobrzynski.com/tips/how-to-move-wordpress-scripts-to-bottom-using-w3-total-cache
Ren says
Thanks for sharing, Tomasz.
Cam says
Great blog Ren, I’ll become your latest frequent visitor 🙂
Thanks for the code, I’d had a version of it in there but this seems much more up to date.
Cheers
Cam