Có thể bạn quan tâm
Đ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.
Lợi ích
- Sẽ không bị báo xóa javascript chặn hiện thị khi test với Google Speed Test.
- 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!
- Bình luận