如何禁止古騰堡區塊編輯器的谷歌字體,參考閱讀:《WordPress技巧-如何禁止古騰堡編輯器加載谷歌字體》,但是這個禁用在有些主題上是無效的。
現象:速度慢,顯示「正在連接ajax.googleapis.com」 ,或谷歌字體 Google Fonts等字眼。
完全禁用谷歌字體雖然在一定程序上提高了網站打開速度,但也可能存在一些問題,大家根據實際情況選擇是否使用吧。如下提供一些方法,僅供參考:
方法:注釋或刪除掉style.css和function.php有關加載Google字體的代碼
注釋或刪除掉style.css和function.php有關加載Google字體的代碼fonts.googleapis.com即可。
在項目文件中搜索fonts.googleapis.com..
把https://fonts.googleapis.com/css 這行代碼注釋掉即可
方法:將以下代碼添加到主題目錄下的functions.php中(推薦)
//關閉谷歌字體
class Disable_Google_Fonts {
public function __construct() {
add_filter( 'gettext_with_context', array( $this, 'disable_open_sans' ), 888, 4 );
}
public function disable_open_sans( $translations, $text, $context, $domain ) {
if ( 'Open Sans font: on or off' == $context && 'on' == $text ) {
$translations = 'off';
}
return $translations;
}
}
$disable_google_fonts = new Disable_Google_Fonts;
方法:通過插件禁用google字體
安裝「Disable Google Fonts」插件。
插件:https://wordpress.org/plugins/disable-google-fonts/
主要針對使用核心程序的。也可以通過如下方法實現對核心程序的處理:
在/wp-includes/script-loader.php中
大約在581行,把//fonts.googleapis.com/…這行代碼刪除即可。直接安裝這個插件也行。
方法:通過插件把google字體本地化
安裝「件OMGF | Host Google Fonts Locally」插件。
這個wordpress插件可以在本地託管谷歌字體,這樣不管是對中文wordpress建站還是外貿建站都可以起到效果,谷歌字體直接從本地加載。
插件可以在wordpress建站後台的插件中心搜索下載。
說明:Increase GDPR compliance, reduce DNS requests and leverage browser cache by automatically downloading Google Fonts to your server.
設置:
如何判斷Google Fonts是否屏蔽?
訪問Google fonts,地址:https://fonts.google.com/
或打開幫助文檔: https://developers.google.com/fonts/docs/getting_started