彻底清除wordpress自带的meta标签

wordpress通过wp_head会自动加载版本信息等各种meta标签,不知从哪一版本开始,head里面会加载emoji的css等,连wp_footer里面都要加载一个wp-embed.min.js,这些都是不需要的。

将下列代码加入到functions.php文件中即可。
  1. function ashuwp_clean_theme_meta(){
  2.   remove_action( 'wp_head', 'print_emoji_detection_script', 71);
  3.   remove_action( 'wp_print_styles', 'print_emoji_styles', 101);
  4.   remove_action( 'wp_head', 'rsd_link', 101);
  5.   remove_action( 'wp_head', 'wp_generator', 101);
  6.   remove_action( 'wp_head', 'feed_links', 21);
  7.   remove_action( 'wp_head', 'feed_links_extra', 31);
  8.   remove_action( 'wp_head', 'index_rel_link', 101);
  9.   remove_action( 'wp_head', 'wlwmanifest_link', 101);
  10.   remove_action( 'wp_head', 'start_post_rel_link', 101);
  11.   remove_action( 'wp_head', 'parent_post_rel_link', 100);
  12.   remove_action( 'wp_head', 'adjacent_posts_rel_link', 100);
  13.   remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 100);
  14.   remove_action( 'wp_head', 'wp_shortlink_wp_head', 100);
  15.   remove_action( 'wp_head', 'rest_output_link_wp_head', 100);
  16.   remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 101);
  17.   remove_action( 'wp_head', 'rel_canonical', 100);
  18. }
  19. add_action( 'after_setup_theme', 'ashuwp_clean_theme_meta' ); //清除wp_head带入的meta标签
  20. function ashuwp_deregister_embed_script(){
  21.   wp_deregister_script( 'wp-embed' );
  22. }
  23. add_action( 'wp_footer', 'ashuwp_deregister_embed_script' ); //清除wp_footer带入的embed.min.js

已有2条评论

发表评论