有很多清洁头解决方案,例如添加钩子以清洁大多数 worpress 默认功能(RSD、RSS 链接等)。在主题 functions.php 中尝试以下钩子:
/*remove actions to clean wp_head*/
remove_action('wp_head', 'wlwmanifest_link'); // remove wlwmanifest.xml (needed to support windows live writer)
remove_action('wp_head', 'wp_generator'); // remove wordpress version
remove_action( 'wp_head', 'wp_resource_hints', 2 );//remove dns prefech
remove_action('wp_head', 'rsd_link'); // remove really simple discovery link
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0 ); // remove shortlink
remove_action( 'wp_head', 'print_emoji_detection_script', 7 ); // remove emojis
remove_action( 'wp_print_styles', 'print_emoji_styles' ); // remove emojis
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head'); // remove the / and previous post links
remove_action('wp_head', 'feed_links', 2); // remove rss feed links
remove_action('wp_head', 'feed_links_extra', 3); // removes all extra rss feed links
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 ); // remove the REST API link
remove_action( 'wp_head', 'wp_oembed_add_discovery_links' ); // remove oEmbed discovery links
remove_action( 'template_redirect', 'rest_output_link_header', 11, 0 ); // remove the REST API link from HTTP Headers
remove_action( 'wp_head', 'wp_oembed_add_host_js' ); // remove oEmbed-specific javascript from front-end / back-end
remove_action('rest_api_init', 'wp_oembed_register_route'); // remove the oEmbed REST API route
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10); // don't filter oEmbed results
您也可以将此片段包装到函数中以使其工作after_theme_setup
或init
可以在 wp_head(); 之后插入其他标签,如charset
和属性。http-equiv
header.php 中的操作。另请查看 wp-includes 模板文件夹文件以找到 wp_head() 操作并删除/注释不必要的操作