移除WordPress自带的各种meta标签

Posted by: Fengjiajun Comments: 0

移除WordPress自带的各种meta标签

默认情况下,WordPress会自动加载各种meta标签,比如emoji表情、feed、版本号等,其实这些完全可以删之:

function clean_theme_meta(){
  remove_action( 'wp_head', 'print_emoji_detection_script', 7, 1);
  remove_action( 'wp_print_styles', 'print_emoji_styles', 10, 1);
  remove_action( 'wp_head', 'rsd_link', 10, 1);
  remove_action( 'wp_head', 'wp_generator', 10, 1);
  remove_action( 'wp_head', 'feed_links', 2, 1);
  remove_action( 'wp_head', 'feed_links_extra', 3, 1);
  remove_action( 'wp_head', 'index_rel_link', 10, 1);
  remove_action( 'wp_head', 'wlwmanifest_link', 10, 1);
  remove_action( 'wp_head', 'start_post_rel_link', 10, 1);
  remove_action( 'wp_head', 'parent_post_rel_link', 10, 0);
  remove_action( 'wp_head', 'adjacent_posts_rel_link', 10, 0);
  remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
  remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0);
  remove_action( 'wp_head', 'rest_output_link_wp_head', 10, 0);
  remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10, 1);
  remove_action( 'wp_head', 'rel_canonical', 10, 0);
}
add_action( 'after_setup_theme', 'clean_theme_meta' );