Skip to content

Instantly share code, notes, and snippets.

@bewho
Forked from dipakcg/functions.php
Created May 14, 2017 10:55
Show Gist options
  • Save bewho/798d1c06105ecbd6acf29acfbcbdf2de to your computer and use it in GitHub Desktop.
Save bewho/798d1c06105ecbd6acf29acfbcbdf2de 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