2023-12-25 6次
/* ------------------移除wp_head()出的的信息------------------ */
// 移除WordPress内联样式
add_action('wp_enqueue_scripts', 'fanly_remove_styles_inline');
function fanly_remove_styles_inline()
{
// 通用输出
wp_deregister_style('global-styles');
wp_dequeue_style('wp-block-library');
wp_deregister_style('classic-theme-styles');
wp_dequeue_style('classic-theme-styles');
}
// 移除Really Simple Discovery
remove_action("wp_head", "rsd_link");
// 移除wp-json链接
remove_action('wp_head', 'rest_output_link_wp_head', 10);
// 移除WordPress版本信息
remove_action("wp_head", "wp_generator");
// 移除Windows Live Writer
remove_action("wp_head", "wlwmanifest_link");
/* ---------移除文章--------- */
// 文章和评论feed
remove_action('wp_head', 'feed_links', 2);
// 分类等feed
remove_action('wp_head', 'feed_links_extra', 3);
// 移除shortlink标签
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
remove_action('template_redirect', 'wp_shortlink_header', 11, 0);
// 去除 wp-embed 功能,加快网页打开速度:
remove_action('rest_api_init', 'wp_oembed_register_route');
remove_filter('rest_pre_serve_request', '_oembed_rest_pre_serve_request', 10, 4);
remove_filter('oembed_dataparse', 'wp_filter_oembed_result', 10);
remove_filter('oembed_response_data', 'get_oembed_response_data_rich', 10, 4);
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');
/* WordPress把前后文、第一篇文章和主页链接全放在meta中。对SEO的帮助并不大,反而让增多head头部信息。建议删除 */
remove_action('wp_head', 'index_rel_link'); //移除主页链接
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
remove_action('wp_head', 'start_post_rel_link', 10, 0);
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0); //删除上下篇文章链接
//移除 API Links
// remove_action("wp_head", "rest_output_link_wp_head", 10);
# 禁用Feed
function wpjam_feed_disabled()
{
wp_die('Feed已经关闭, 请访问网站<a href="" . get_bloginfo("url") . "">首页</a>!');
}
add_action("do_feed", "wpjam_feed_disabled", 1);
add_action("do_feed_rdf", "wpjam_feed_disabled", 1);
add_action("do_feed_rss", "wpjam_feed_disabled", 1);
add_action("do_feed_rss2", "wpjam_feed_disabled", 1);
add_action("do_feed_atom", "wpjam_feed_disabled", 1);
/**去除window._wpemojiSettings**/
remove_action('admin_print_scripts', 'print_emoji_detection_script');
remove_action('admin_print_styles', 'print_emoji_styles');
remove_action('wp_head', 'print_emoji_detection_script', 7);
remove_action('wp_print_styles', 'print_emoji_styles');
remove_filter('the_content_feed', 'wp_staticize_emoji');
remove_filter('comment_text_rss', 'wp_staticize_emoji');
remove_filter('wp_mail', 'wp_staticize_emoji_for_email');
/* ------------------------------------ */