Hướng dẫn loại bỏ code không cần thiết trong header của WordPress

Làm sạch header trong WordPress

Hiện tại thiết kế web trên mã nguồn WordPress khá phổ biến, do là mã nguồn mở nên có rất nhiều phần code thừa được WordPress đưa vào phần header của web, những phần code thừa làm ảnh hưởng đến tốc độ load trang đễn đến điểm SEO bị thấp. Hôm nay Win Win media hướng dẫn các bạn loại bỏ bỏ những phần code thừa đó.

Những code thừa trong WordPress

Really simple discovery link (rsd_link)

WordPress version (wp_generator) : phiên bản wordpress  <meta name=”generator” content=”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)

Hướng dẫn loại bỏ code không cần thiết trong header của WordPress
Hướng dẫn loại bỏ code không cần thiết trong header của WordPress

Loại bỏ code không cần thiết trong thẻ header của WordPress

Để 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

Sau đó bạn lưu lại là ok

Xem thêm: Sitemap là gì ?, cách tạo sitemap

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

Trả lời

Email của bạn sẽ không được hiển thị công khai. Các trường bắt buộc được đánh dấu *