Di chuyển Javascript xuống footer trong WordPress

Cập nhật lần cuối 28/04/2015 by trong WordPress vào 28/04/2015 có 4134 Views

Đoạn code này sẽ giúp các bạn di chuyển toàn bộ Javascript của plugin hay mặc định của wordpress xuống footer.

move_jquery_to_footer

Lợi ích

  1. Sẽ không bị báo xóa javascript chặn hiện thị khi test với Google Speed Test.
  2. Load web nhanh hơn khi tất cả Jquery ở footer.

Code di chuyển Javascript xuống footer

các bạn thêm đoạn code dưới đây vào file functions.php của theme đang chạy nhé.

function footer_enqueue_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('after_setup_theme', 'footer_enqueue_scripts');

Tham khảo: http://www.kevinleary.net/move-javascript-bottom-wordpress/

Chúc các bạn thành công!

5/5 - (5 votes)
  • Bình luận
Sản phẩm nổi bật của Toản
x