If you want to loads all JavaScript files in Footer section, then this question is for you. We have shared a WordPress snippet to move all JavaScript files from Header to Footer section for all pages.
Copy the below code and add at the end of your theme’s functions.php file and save it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 | /** * Custom script to move all JavaScript files from the Head to the Footer section. */ function remove_head_scripts() { 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', 'remove_head_scripts' ); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.