17713433920 info@mac163.com

WordPress建站,方是方便,但由于WordPress是一个国际化的开源程序,在网页Head区域代码里会产生很多符合国际标准的标签(如果你用了国内人士开发的主题,此现象不易出现),这些标签每个都有自己的意义和用途,但在中国的互联网环境下,则有很多是用不到的。如果在网站页面里加载太多的标签,会影响页面的加载速度,如果确定无用的,手狠一点,该删除且删除。

去除WordPress页眉区域代码无用标签关闭无用功能

那到底哪些Head区域标签可以删除呢?Mac163从自己的几个网站中,找出大部分在用的无用标签/功能。

去除WORDPRESS自带的 Emoji
// WordPress Emoji Delete
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');
add_filter( 'emoji_svg_url', create_function( '', 'return false;' ) );//禁用emoji预解析

去除 XMLRPC, WLW, Generator, Feeds 和 ShortLink
去掉这些标记,向 function.php(在你所使用的模板主题目录下) 文件里添加下面的代码:

remove_action('wp_head', 'rsd_link'); //removes EditURI/RSD (Really Simple Discovery) link.
remove_action('wp_head', 'wlwmanifest_link'); //removes wlwmanifest (Windows Live Writer) link.
remove_action('wp_head', 'wp_generator'); //removes meta name generator.
remove_action('wp_head', 'wp_shortlink_wp_head'); //removes shortlink.
remove_action( 'wp_head', 'feed_links', 2 ); //removes feed links.
remove_action('wp_head', 'feed_links_extra', 3 ); //removes comments feed.

去除 Previous 和 Next 文章链接
去掉文章的上一篇和下一篇链接,向 function.php 文件里添加下面的代码:

/*Removes prev and next links*/
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head');

去除 XFN (XHTML Friends Network) Profile 链接 和 Pingback URL
这个 rel=profile 链接和 rel=Pingback 标记可以从header.php文件里直接删除。做法是,打开Wordperss主题里的header.php文件,删除下面两行:

<link rel="profile" href="http://gmpg.org/xfn/11"> 
<link rel="pingback" href="<?php bloginfo( 'pingback_url' ); ?>">

禁用REST API功能

//禁用REST API功能代码
add_filter('rest_enabled', '__return_false');
add_filter('rest_jsonp_enabled', '__return_false');

移除wp-json链接

//移除wp-json链接的代码
remove_action( 'wp_head', 'rest_output_link_wp_head', 10 );
remove_action( 'wp_head', 'wp_oembed_add_discovery_links', 10 );

根据上边的内容,对比检查自己WORDPRESS网站首页源代码里的头部标签(head区域),有选择地删除即可。


微信二维码

微信扫描二维码联系我们!
我们在微信上24小时期待你的声音
提供外贸路由器设备产品,轻松翻墙,解答:WP主题推荐,WP网站建设,Google SEO,百度SEO,专业服务器环境搭建等!


需要提供WordPress主题/插件的汉化服务可以随时联系我们!另外成品WordPress网站以及半成品WordPress网站建设,海外Google SEO优化托管服务,百度SEO优化托管服务,Centos/Debian服务器WP专用环境搭建,WP缓存服务器搭建,我们都是你的首选,拥有多年WP开源程序服务经验,我们一直在坚持客户体验,没有最好,只有更好!
回到顶部