wordpress如何彻底清除自带的meta标签

发布时间:

wordpress头部的代码非常多,包括WordPress版本,前后文、第一篇文章、主页meta信息等各种冗余代码,这些对博主来说是没有意义的,也对网站的安全有一定的影响,也一度不知道这些代码是有什么作用、怎么来的和怎么删除。

wordpress如何彻底清除自带的meta标签

将下列代码加入到functions.php文件中即可:

function ashuwp_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', 'ashuwp_clean_theme_meta' ); //清除wp_head带入的meta标签
function ashuwp_deregister_embed_script(){
wp_deregister_script( 'wp-embed' );
}
add_action( 'wp_footer', 'ashuwp_deregister_embed_script' ); //清除wp_footer带入的embed.min.js