wordpress清除头部特殊的谷歌字体fonts.googleapis.com样式引用

IT资讯
IT资讯
IT资讯
1172
文章
239
评论
2019-07-2702:44:23
评论
3,074 2664字

在优化wordpress的时候,发现加载速度总是上不来,经查发现是因为所安装的插件在网站头部加了特殊的谷歌字体引用方式,但是传统的谷歌字体和地图删除插件或是代码根本对这种形式的谷歌字体引用链接无效....

弄了很久,终于可以手动的在当前主题函数代码当中添加如下代码来清除这个问题了:

案例一:

wordpress清除头部特殊的谷歌字体fonts.googleapis.com样式引用

解决方案之代码如下:

//清除头部谷歌字样样式引用(fonts.googleapis.com)
function coolwp_remove_google_fonts_1_from_wp_core() {
    wp_deregister_style( 'google-fonts-1' );
    wp_register_style( 'google-fonts-1', false );
    wp_enqueue_style('google-fonts-1','');
}
add_action( 'init', 'coolwp_remove_google-fonts-1_from_wp_core' );

 

 

 

案例二: wordpress清除头部特殊的谷歌字体fonts.googleapis.com样式引用

解决方案之代码如下:

//清除头部谷歌字样样式引用(fonts.googleapis.com)

function coolwp_remove_et_gf_chinese_from_wp_core() {
wp_deregister_style( 'et-gf-chinese' );
wp_register_style( 'et-gf-chinese', false );
wp_enqueue_style('et-gf-chinese','');
}
add_action( 'init', 'coolwp_remove_et_gf_chinese_from_wp_core' );

 

 

 

怎么样,学到技巧了吗? :)

 

另外,附上传统清除谷歌字体和谷歌地图的代码:

方法一:

//WordPress 后台禁用Google Open Sans字体,加速网站
add_filter( 'gettext_with_context', 'wpdx_disable_open_sans', 888, 4 );
function wpdx_disable_open_sans( $translations, $text, $context, $domain ) {
  if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
    $translations = 'off';
  }
  return $translations;
}

 

 

方法二:

/** 禁用谷歌在线样式 **/
function remove_open_sans() {
    wp_deregister_style( 'open-sans' );
    wp_register_style( 'open-sans', false );
    wp_enqueue_style('open-sans','');
}
add_action( 'init', 'remove_open_sans' );

 

 

 

 

 

另外,再附加清除wordpress头部多余代码的代码:

//去掉头部多余代码来完成站点加速
//remove_action( 'wp_head', 'wp_enqueue_scripts', 1 ); //Javascript的调用
remove_action( 'wp_head', 'feed_links', 2 ); //移除feed
remove_action( 'wp_head', 'feed_links_extra', 3 ); //移除feed
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', 'locale_stylesheet' );
remove_action('publish_future_post','check_and_publish_future_post',10, 1 );
remove_action( 'wp_head', 'noindex', 1 );
remove_action( 'wp_head', 'wp_print_styles', 6 );//载入css
remove_action( 'wp_head', 'wp_generator' ); //移除WordPress版本
remove_action( 'wp_head', 'rel_canonical' );
remove_action( 'wp_footer', 'wp_print_footer_scripts' );
remove_action( 'wp_head', 'wp_shortlink_wp_head', 10, 0 );
remove_action( 'template_redirect', 'wp_shortlink_header', 11, 0 );
add_action('widgets_init', 'my_remove_recent_comments_style');
function my_remove_recent_comments_style() {
global $wp_widget_factory;
remove_action('wp_head', array($wp_widget_factory->widgets['WP_Widget_Recent_Comments'] ,'recent_comments_style'));
}

 

 

 

 

 

 

 

 

 

  • Copyright ©  PC在线云端  版权所有.
  • 转载请务必保留本文链接:https://nrcs.xyz/web/wordpress_web/8303.html
WordPress 使用 Github & JsDelivr 加速静态文件 WEB技术

WordPress 使用 Github & JsDelivr 加速静态文件

一个网站的打开速度至关重要,会直接影响搜索引擎排名和用户体验。如果您的网站加载越慢,用户离去的就会越快,而用户又是我们生存的根本。 当然网站加载速度受很多因素影响,今天我们使用 Github &...
Orgorg速率最高可达1000Mbps,流畅观看Youtube 4K、TikTok,支持 Windows、Android、iOS、Mac,支持 微信、支付宝 付款!
全球数据中心,多点BGP保证速度,无视晚高峰,全天4K秒开,IPLC专线无惧封锁
全IEPL /青云跨境,高峰时期稳定8K播放,流媒体影视, ChatGPT 解锁保障,客户端无日志保护您的隐私安全,稳定运行5年+
匿名

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: