WordPress从头部删除了多余的附加组件,如js、css和feed

2021-08-11 0 1,081

我们开发WordPress 主题的时候,要小心朋友,或者发现如果网站头部加载了头部页面,系统会有很多加载项,比如自己的css、js、feed、style。
这些加载项很多都是不需要加载的,那么如何删除这些冗余的表头信息呢?
方法很简单,网上有很多教程。今天汇站网为你整理。

代码

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




	
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文件中, 保存后在看看网站的代码。

head 头部是不是少了很多多余加载项信息?

本文章已结束,如转载请注明:汇站网 » WordPress 从头部删除了多余的附加组件,如 js、css 和 feed

收藏 (0)

微信支付 微信扫一扫

支付宝支付 支付宝扫一扫

打赏二维码
点赞 (0)

站长资源下载中心-找源码上汇站

常见问题
  • 如果付款后没有弹出下载页面,多刷新几下,有问题联系客服!
查看详情
  • 本站所有资源版权均属于原作者所有,这里所提供资源均只能用于参考学习用,请勿直接商用。若由于商用引起版权纠纷,一切责任均由使用者承担。
查看详情

相关文章

联系官方客服

为您解决烦忧 - 24小时在线 专业服务