Mặc định các thư viện JavaScript sẽ được đặt bên trong thẻ <head></head>, để có thể đặt nó nằm ở phía dưới footer, tại functions.php các bạn sử dụng đoạn code như sau.
/**
* Automatically move JavaScript code to page footer, speeding up page loading time.
*/
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');
Chúc các bạn thành công!
Bình luận