最新公告
  • 欢迎您光临5466,本站秉承服务宗旨 履行“站长”责任,销售只是起点 服务永无止境!进入交流论坛
  • WordPress移除head头部js、css、feed等多余加载项_52弹弹堂-5466shop.cn

    WordPress移除head头部js、css、feed等多余加载项_52弹弹堂-5466shop.cn 最后编辑:2020-08-28

    在我们开发WordPress主题时,细心的小伙伴或发现网站头部如果加载head页面就会出现很多系统自带的加载项目,例如自带的cssjs、feed、style等多余信息

    这些加载项目很多是没有必要加载的,那么我们如何将这些多余的head头部信息移除呢?

    方法很简单,网上针对此类WordPress优化的教程也很多,今天路途吧lutu88.com就给大家整理下。

    我们先看看移除多余加载项之前的代码截图

    WordPress移除head头部js、css、feed等多余加载项

    解决方法

    //去除头部多余加载信息
    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移除head头部js、css、feed等多余加载项

    猜你喜欢

    猜你在找

    1. 本站所有资源来源于用户上传和网络,因此不包含技术服务请大家谅解!如有侵权请邮件联系客服!7345947@qq.com 2. 本站不保证所提供下载的资源的准确性、安全性和完整性,资源仅供下载学习之用!如有链接无法下载、失效或广告,请联系客服处理,有奖励! 3. 您必须在下载后的24个小时之内,从您的电脑中彻底删除上述内容资源!如用于商业或者非法用途,与本站无关,一切后果请用户自负! 4. 如果您也有好的资源或教程,您可以投稿发布,成功分享后有站币奖励和额外收入!
    5466资源网 » WordPress移除head头部js、css、feed等多余加载项_52弹弹堂-5466shop.cn
    • 2020-08-28Hi,初次和大家见面了,请多关照!

    发表回复

    • 383会员总数(位)
    • 41554资源总数(个)
    • 0本周发布(个)
    • 0 今日发布(个)
    • 1154稳定运行(天)

    提供最优质的资源集合

    立即查看 了解详情