Tuesday, February 6, 2024

Làm sạch header trong WordPress

Làm sạch header trong WordPress là như thế nào?

WordPress đã mặc định chèn thêm rất nhiều đoạn mã không thực sự cần thiết vào trong phần header của mã nguồn HTML, đôi khi chúng ta không cần tiêu dùng tới nó.

Mình sẽ nói về n hững thành phần nên loại bỏ để làm sạch header

Chúng bao gồm:

  • Really simple discovery link (rsd_link)
  • WordPress version (wp_generator) : phiên bản wordpress  <meta name=”generatorcontent=”WordPress 5.7.2” />
  • RSS feed links (feed_links và feed_links_extra)
  • Link to index page (index_rel_link)
  • wlwmanifest.xml (wlwmanifest_link)
  • Random post link (start_post_rel_link)
  • Parent post link (parent_post_rel_link)
  • Next and previous post links (adjacent_posts_rel_link)
  • WP shortlink (wp_shortlink)

Để loại bỏ tất cả các đoạn mã kể trên trong header của WordPress, các bạn chỉ cần thêm code sau đây vào trong file functions.php của theme hoặc child theme đang tiêu dùng:

remove_action('wp_head', 'rsd_link'); // remove really simple discovery linkremove_action('wp_head', 'wp_generator'); // remove wordpress versionremove_action('wp_head', 'feed_links', 2); // remove rss feed links (make sure you add them in yourself if youre using feedblitz or an rss service)remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed linksremove_action('wp_head', 'index_rel_link'); // remove link to index pageremove_action('wp_head', 'wlwmanifest_link'); // remove wlwmanifest.xml (needed to support windows live writer)remove_action('wp_head', 'start_post_rel_link', 10, 0); // remove random post linkremove_action('wp_head', 'parent_post_rel_link', 10, 0); // remove parent post linkremove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // remove the next and previous post linksremove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 );remove_action( 'wp_head', 'print_emoji_detection_script', 7 );remove_action( 'wp_print_styles', 'print_emoji_styles' );remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0); // Remove shortlink

Làm sạch header trong WordPress

Lời kết

Như vậy mình đã chia sẻ  làm sạch header trong WordPress 1 thủ thuật rất đơn giản nó làm tối ưu trang của bạn hơn.

Nếu các bạn thấy hay có thể theo dõi chuyên mục thủ thuật wordpress để biết thêm nhiều kiến thức mới nha.

Hãy xem thêm các bài đăng khác trên Website của chúng tôi để nhận được những bài viết mới nhất nhé.

Chúc bạn có những thêm những kiến thức hữu ích về wordpress cho việc học tập và nghiên cứu của mình.


0 nhận xét:

Post a Comment