最近很多朋友都在問為什麼 wordpress 的開啟速度非常慢,有時候需要 10 幾秒鐘才能開啟,很多人都想解決這個問題,但是又不知道該如何下手,其實解決這個問題非常簡單,因為 wordpress 預設是會載入 google 字型的,而且 google 眾所周知的,在國內會被牆,所以拖慢了你網站或部落格的開啟速度,下面,我們就這個問題提供三種解決方法:
方法一:安裝外掛 Disable Google Fonts 或 Remove Open Sans font Link from WP core 等相關外掛後啟用外掛即可,安裝方法可直接在你的 wordpress 管理後臺安裝外掛中搜尋外掛名直接安裝即可!半夏推薦各位使用這種方法,簡單,快捷,不會受 wordpress 升級或切換主題等問題的影響。
方法二:程式碼到當前所用的主題的 functions.php 中即可,程式碼如下:
/** * WordPress 後臺停用 Google Open Sans 字型,加速網站 * http://www.wpdaxue.com/disable-google-fonts.html */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;}
或者使用如下程式碼也可:
wp_deregister_style(‘open-sans’);
wp_register_style(‘open-sans’,false);
wp_enqueue_style(‘open-sans’,”);
}
add_action(‘init’,’remove_open_sans’);
方法三:Google Fonts 換為 360CDN,在當前的主題檔案中新增如下程式碼即可,程式碼如下:
<?php/* Plugin Name: DW Replace Open Sans Plugin URI: http://devework.com/replace-open-sans.html Description: 將 WordPress 後臺中的 open-sans 字型載入源從 Google Fonts 替換為 360 的 CDN 載入源。 Author: Jeff Author URI: http://devework.com/ Version: 1.0 Text Domain: dw-replace-open-sans */ function devework_replace_open_sans() { wp_deregister_style(‘open-sans’); wp_register_style( ‘open-sans’, ‘//fonts.useso.com/css?family=Open+Sans:300italic,400italic,600italic,300,400,600’ ); wp_enqueue_style( ‘open-sans’);}add_action( ‘wp_enqueue_scripts’, ‘devework_replace_open_sans’ );add_action(‘admin_enqueue_scripts’, ‘devework_replace_open_sans’);?>
以上,自己去試試吧。