I'm using the 'Bones' theme in my latest WordPress site, and when I run the site through Google PageSpeed, I receive the following error:
Eliminate render-blocking JavaScript and CSS in above-the-fold content:
https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js/ https://www.default.com/…includes/js/jquery/jquery-migrate.min.js https://ajax.googleapis.com/…ax/libs/jqueryui/1.10.3/jquery-ui.min.js https://www.default.com/…lugins/node.tmp/js/jquery.transit.min.js https://www.default.com/…gins/node.tmp/js/jquery.touchwipe.min.js https://www.default.com/…ntent/plugins/node.tmp/js/jquery.sidr.js https://www.default.com/…ugins/node.tmp/js/mobile.nav.frontend.js https://www.default.com/…/library/js/libs/modernizr.custom.min.js
How can I load these scripts in the footer instead of the header as the theme is currently doing?
The following is included in bones.php, which initializes the theme:
/*********************
SCRIPTS & ENQUEUEING
*********************/
// loading modernizr and jquery, and reply script
function bones_scripts_and_styles() {
global $wp_styles; // call global $wp_styles variable to add conditional wrapper around ie stylesheet the WordPress way
if (!is_admin()) {
// modernizr (without media query polyfill)
wp_register_script( 'bones-modernizr', get_stylesheet_directory_uri() . '/library/js/libs/modernizr.custom.min.js', array(), '2.5.3', false );
// register main stylesheet
wp_register_style( 'bones-stylesheet', get_stylesheet_directory_uri() . '/library/css/style.css', array(), '', 'all' );
// ie-only style sheet
wp_register_style( 'bones-ie-only', get_stylesheet_directory_uri() . '/library/css/ie.css', array(), '' );
// comment reply script for threaded comments
if ( is_singular() AND comments_open() AND (get_option('thread_comments') == 1)) {
wp_enqueue_script( 'comment-reply' );
}
//adding scripts file in the footer
wp_register_script( 'bones-js', get_stylesheet_directory_uri() . '/library/js/scripts.js', array( 'jquery' ), '', true );
// enqueue styles and scripts
wp_enqueue_script( 'bones-modernizr' );
wp_enqueue_style( 'bones-stylesheet' );
wp_enqueue_style( 'bones-ie-only' );
$wp_styles->add_data( 'bones-ie-only', 'conditional', 'lt IE 9' ); // add conditional wrapper around ie stylesheet
/*
I recommend using a plugin to call jQuery
using the google cdn. That way it stays cached
and your site will load faster.
*/
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'bones-js' );
}
}