WordPress去掉head头部js/css/feed/dns/版本号等多余加载标签

对于有轻微强迫症的主题君来说,是在是看不下去WordPress自带的head头部js、css等多余加载项。

其实head头部区域很多加载的文件都是没有比较加载的,例如:WordPress版本号、rel=canonical、dns-prefetch等等,那么我们如何能将这些head头部区域多余加载项给去掉呢?

方法很简单,几行代码就能够去掉,今天主题君就给大家整理下。

//去除头部多余加载信息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 );//移除文章和评论feedremove_action( \\\'wp_head\\\', \\\'feed_links_extra\\\', 3 ); //移除分类等feedremove_action( \\\'wp_head\\\', \\\'rest_output_link_wp_head\\\', 10 ); //移除wp-jsonremove_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=canonicalremove_action( \\\'wp_head\\\', \\\'wp_shortlink_wp_head\\\', 10, 0 ); //rel=shortlink//remove_action( \\\'wp_head\\\', \\\'wp_print_styles\\\', 8 ); //移除后台插件加载cssremove_action( \\\'wp_head\\\', \\\'print_emoji_detection_script\\\', 7 );//移除emoji载入jsremove_action( \\\'admin_print_scripts\\\', \\\'print_emoji_detection_script\\\' );//emoji载入jsremove_action( \\\'wp_print_styles\\\', \\\'print_emoji_styles\\\' );//移除emoji载入cssremove_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,看看我们的头部区域代码是不是少了很多多余加载项信息?

扫码关注wp主题君

精选优质免费WordPress主题模板,分享最新WordPress实用建站教程!

记住我们的网址:ztJun.com

本文来源于 网络,由本站搜集发布,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系本站核实处理。如需转载,请注明文章来源。

© 版权声明
THE END
喜欢就支持一下吧
点赞6 分享