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 sử 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 sử dụng:

remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
remove_action('wp_head', 'wp_generator'); // remove wordpress version

remove_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 links

remove_action('wp_head', 'index_rel_link'); // remove link to index page
remove_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 link
remove_action('wp_head', 'parent_post_rel_link', 10, 0); // remove parent post link
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0); // remove the next and previous post links
remove_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ờ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 follow fanpage để nhận được những bài viết mới nhất nhé : Hocwordpress Group

Chúc bạn có những kiến thức về  wordpress thú vị và hay ho !

 
5 1 vote
Đánh giá bài viết
Leave a Comment