去除wordpress头部无用代码

添加到模版functions.php文件头

//去除头部冗余代码
remove_action('wp_head', 'feed_links_extra', 3);
remove_action('wp_head', 'feed_links', 2);
remove_action('wp_head', 'rsd_link'); //移除离线编辑器开放接口
remove_action('wp_head', 'wlwmanifest_link'); //移除离线编辑器开放接口
remove_action('wp_head', 'index_rel_link'); //本页链接
remove_action('wp_head', 'parent_post_rel_link'); //清除前后文信息
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');
remove_action('wp_head', 'rel_canonical'); //本页链接
remove_action('wp_head', 'wp_generator'); //移除WordPress版本号
remove_action('wp_head', 'wp_shortlink_wp_head'); //本页短链接
remove_action( 'template_redirect','wp_shortlink_header', 11, 0);
add_filter('xmlrpc_enabled', '__return_false');
add_filter('embed_oembed_discover', '__return_false');
remove_action('wp_head', 'wp_oembed_add_discovery_links');
remove_action('wp_head', 'wp_oembed_add_host_js');
remove_filter('pre_oembed_result', 'wp_filter_pre_oembed_result', 10);
// 屏蔽 REST API
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');
// 移除头部 wp-json 标签和 HTTP header 中的 link
remove_action('wp_head', 'rest_output_link_wp_head', 10);
remove_action( 'template_redirect','rest_output_link_header', 11, 0 );//屏蔽WP自带API产生的头部信息
//清除wp_footer带入的embed.min.js
function git_deregister_embed_script() {
wp_deregister_script('wp-embed');
}
add_action('wp_footer', 'git_deregister_embed_script');

add_action( 'wp_enqueue_scripts', 'mt_enqueue_scripts', 1 );
function mt_enqueue_scripts() {
wp_deregister_script('jquery');
}

from  kratos

/**
* Remove the head code
*
* @author Vtrois <seaton@vtrois.com>
* @license GPL-3.0
*/
add_filter( ’emoji_svg_url’, ‘__return_false’ );
add_filter( ‘show_admin_bar’, ‘__return_false’ );
remove_action( ‘wp_head’, ‘wp_print_head_scripts’, 9 );
remove_action( ‘wp_head’, ‘wp_generator’ );
remove_action( ‘wp_head’, ‘rsd_link’ );
remove_action( ‘wp_head’, ‘wlwmanifest_link’ );
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 );
remove_action( ‘wp_head’, ‘rel_canonical’ );
remove_action( ‘wp_head’, ‘feed_links’, 2 );
remove_action( ‘wp_head’, ‘feed_links_extra’, 3 );
remove_action(‘admin_print_scripts’, ‘print_emoji_detection_script’);
remove_action(‘admin_print_styles’, ‘print_emoji_styles’);
remove_filter(‘the_content’, ‘wptexturize’);
remove_filter(‘comment_text’, ‘wptexturize’);
remove_action(‘wp_head’, ‘print_emoji_detection_script’, 7);
remove_action(‘wp_print_styles’, ‘print_emoji_styles’);
remove_action(’embed_head’, ‘print_emoji_detection_script’);
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’);

点赞