对于一些有强迫症的人来说,会看不惯WordPress头部自带的js、css等多余加载项,就会想着去除,那么如何去除WordPress头部自带的js/css/feed/dns/版本号?

其实head头部区域很多加载的文件都是没有比较加载的,例如:WordPress版本号、rel=canonical、dns-prefetch等等,去除方法很简单,几行代码就能够去掉,今天WordPress主题站就给大家整理下。

//去除头部多余加载信息

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_generator\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );//移除WordPress版本

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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’feed_links\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 2 );//移除文章和评论feed

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’feed_links_extra\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 3 ); //移除分类等feed

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’rest_output_link_wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10 ); //移除wp-json

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’print_emoji_detection_script\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 7 ); //头部的JS代码

add_filter( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’show_admin_bar\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’__return_false\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );//移除wp-json链接

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’rel_canonical\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ ); //rel=canonical

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_shortlink_wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10, 0 ); //rel=shortlink

//remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_print_styles\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 8 ); //移除后台插件加载css

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’print_emoji_detection_script\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 7 );//移除emoji载入js

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’admin_print_scripts\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’print_emoji_detection_script\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );//emoji载入js

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_print_styles\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’print_emoji_styles\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );//移除emoji载入css

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’admin_print_styles\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’print_emoji_styles\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’ );

remove_action( \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’rest_output_link_wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’, 10 );

remove_action(\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_head\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’wp_resource_hints\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\’,2);//移除dns-prefetch

使用方法

将上面代码添加到主题的functions.php文件中, 保存后打开网站f12,看看我们的头部区域代码是不是少了很多多余加载项信息。

相关新闻

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注

联系我们

联系我们

151-1101-0018

在线咨询:
邮件:30115776@qq.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信
关注微信
分享本页
返回顶部