Có thể bạn quan tâm
- Giới hạn độ dài tiêu đề bài viết trong wordpress khi dùng hàm the_title()
- Hiển thị comment form ra ngoài trang chủ | Display comment form on index page
- Xóa thẻ p xung quanh thẻ img trong WordPress
- Flatsome: Chuyển phân trang của bình luận bài viết từ “kiểu next/prev” sang “tải thêm bằng ajax”
- Hiển thị toàn bộ các bài viết có cùng taxonomy
Đ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