Skip to content

Instantly share code, notes, and snippets.

@dipakcg
Last active May 14, 2017 10:55
Show Gist options
  • Save dipakcg/f0950d972d687be415c412191e7c5b0f to your computer and use it in GitHub Desktop.
Save dipakcg/f0950d972d687be415c412191e7c5b0f to your computer and use it in GitHub Desktop.
WordPress - Force all scripts to footer
/* ******************
When considering performance speed, you may want to keep JS scripts organized beneath your overall page HTML.
This snippet allows most of the DOM to finish loading before running any dynamic scripts.
****************** */
function dcg_move_scripts_to_footer() {
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);
}
}
add_action( 'wp_enqueue_scripts', 'dcg_move_scripts_to_footer' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment