解決WordPress加載的google字體-網站打開過慢的問題

最近wordpress用戶反饋打開刷新網站包括后臺訪問,都非常緩慢,用chrome觀察,發現網站在打開fonts.googleapis這個項目花費了20多秒,查下下fonts.googleapis這個項目是wordpress加載google字體的,而最近google全面被墻,估計就是導致眾多wordpress打開緩慢的原因。而wordpress大概從wp-3.8開始會自動加載Open Sans字體,并引用Google上面的CSS樣式,造成了網站后臺也是打開緩慢,令人發指。
fonts.googleapis解決方案一:
在主題中的functions.php文件末尾加上一下代碼之一即可。此方法僅在前臺有效,在后臺界面無效,因為僅修改主題代碼。

1. 代碼一
// Remove Open Sans that WP adds from frontend
if (!function_exists(‘remove_wp_open_sans’)) :
function remove_wp_open_sans() {
wp_deregister_style( ‘open-sans’ );
wp_register_style( ‘open-sans’, false );
}
add_action(‘wp_enqueue_scripts’, ‘remove_wp_open_sans’);
// Uncomment below to remove from admin
// add_action(‘admin_enqueue_scripts’, ‘remove_wp_open_sans’);
endif;
2. 代碼二
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’ );
fonts.googleapis解決方案二:插件過濾
此方法在前臺和后臺均有效。
1. 插件一
插件:Remove Open Sans font Link from WP core
簡介:移除WP核心的谷歌字體鏈接.
2. 插件二
插件:Disable Google Fonts


 

本站使用的全部代碼如下:

//禁止WordPress后臺加載谷歌字體
function coolwp_remove_open_sans_from_wp_core() {
wp_deregister_style( 'open-sans' );
wp_register_style( 'open-sans', false );
wp_enqueue_style('open-sans','');
}
add_action( 'init', 'coolwp_remove_open_sans_from_wp_core' );
//禁止WordPress后臺加載谷歌字體

// Remove Open Sans that WP adds from frontend去掉加載谷歌字體
if (!function_exists(‘remove_wp_open_sans’)) :
function remove_wp_open_sans() {
wp_deregister_style( ‘open-sans’ );
wp_register_style( ‘open-sans’, false );
}
add_action(‘wp_enqueue_scripts’, ‘remove_wp_open_sans’);
// Uncomment below to remove from admin
// add_action(‘admin_enqueue_scripts’, ‘remove_wp_open_sans’);
endif;
//去掉加載谷歌字體



更多閱讀:

wordpress后臺登陸緩慢,原因是谷歌Open Sans字體無法加載

完美解決wordpress鏈接google字體慢的問題

禁用谷歌字體加快wordpress網頁打開速度!

禁止WordPress后臺加載谷歌字體

Google服務被“封”,服務器移到美國了,影響到使用谷歌字體的wordpress站長們了,本文為解決辦法。

 
  • 本文由 米粒在線 發表于 2014年6月18日20:50:55
  • 轉載請務必保留本文鏈接:http://m.bjmhhq.com/24639.html
百科知道

徹底解決AMD顯卡win10開機黑屏問題

遇上個AMD R7 350 顯卡 偶爾開機到了logo之后黑屏,找了各種法子沒解決,看到了這個辦法。試試看。來自小櫻看科技的公眾號。這邊做一下記錄避免丟了。謝謝。小櫻的辦公用電...

發表評論

匿名網友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:
確定

拖動滑塊以完成驗證