Last active
May 14, 2017 10:55
-
-
Save dipakcg/f0950d972d687be415c412191e7c5b0f to your computer and use it in GitHub Desktop.
WordPress - Force all scripts to footer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ****************** | |
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