[WordPress] 外掛分享: ACF: Google Font Selector

首頁外掛目錄 › ACF: Google Font Selector
WordPress 外掛 ACF: Google Font Selector 的封面圖片
3,000+
安裝啟用
★★★☆☆
3.5/5 分(6 則評價)
3978 天前
最後更新
問題解決
WordPress 3.5+ v3.0.1 上架:2014-02-03

內容簡介

這個外掛可以讓你創建一個 Google 字體選擇欄位,並提供不同的選項。此外,外掛還會在主題標頭中創建字體請求,以自動加載字體。你可以分別選擇字體變體和字符集,以使字體加載更加靈活和優化。

將字體選項添加到任何選項頁面都會被自動載入。將字體添加到文章頁面中將僅在顯示該特定文章時自動載入。

Google API 金鑰

為了從 Google 獲取字體列表,你需要 API 金鑰。這是免費且易於操作的,可以參考這份指南來獲取 API 金鑰。

ACF 相容性

此 ACF 欄位類型與 ACF 4 和 ACF 5 均相容。

感謝

感謝Advanced Custom Fields提供的優秀基礎插件。
感謝Iconjam提供的 T 標誌。

使用方法

安裝完成後,Google 字體列表將從插件中包含的靜態文件中檢索。如果你想從 Google API 中提取列表,你需要在管理員中定義你的 API 金鑰。你可以在「設置」 > 「Google 字體選擇器」中進行設置。

針對開發人員

你可以設置一些更高級的控件,以使插件更符合你的需求。如果你想硬編碼 API 金鑰,並禁用用戶查看提示和設置面板,你可以定義ACFGFS_API_KEY常量。

define( 'ACFGFS_API_KEY', 'your_google_api_key' );

ACFGFS_REFRESH 常量可以控制插件檢查 Google API 更新的頻率。值以秒為單位,86400 表示一天。預設值為 7 天。

define( 'ACFGFS_REFRESH', 259200 );

如果你想禁用字體的自動加載,你可以使用 ACFGFS_NOENQUEUE 常量。當未定義此常量時,字體會自動加載。定義常量可以禁用加載。

define( 'ACFGFS_NOENQUEUE', true );

如果你想要修改頁面上載入的字體,你可以使用 acfgfs/enqueued_fonts 過濾器。這應返回一個陣列,其中包含所需的字體變體和子集,例如:

array(
'font' => 'Open Sans',
'variants' => array( 'regular', '700' ),
'subsets' => array( 'latin' )
)

3.0.1 中新增了控制下拉列表中顯示字體的功能。如果你只想讓用戶訪問 Google 字體的一小部分,你可以使用 acfgfs/font_dropdown_array 過濾器來修改用於生成下拉列表的陣列。請返回一個鍵和值都是字體名稱的陣列。

add_filter( 'acfgfs/font_dropdown_array', 'my_font_list' );
function my_font_list( $fonts ) {
$fonts = array(
'Raleway' => 'Raleway',
'Lato' => 'Lato'
);
return $fonts;
}

外掛標籤

開發者團隊

⬇ 下載最新版 (v3.0.1) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「ACF: Google Font Selector」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

This plugin allows you to create a Google font selector field with different options. The plugin also creates the font request in the theme header to autoload the fonts if you’d like. Font variants and charsets can be selected separately to make font loading more flexible and optimized.
Font options added to any options page will always be enqueued. Any fonts added to post pages will only be enqueued when that specific post is displayed.
Google API Key
To grab the font list from Google you’ll need an API key. This is free and easy to do, take a look at this guide to get an API key.
ACF Compatibility
This ACF field type is compatible with both ACF 4 and ACF 5.
Thanks

Advanced Custom Fields for the awesome base plugin.
Iconjam for the T icon.

Usage
Once installed the list of Google Fonts will be retrieved from a static file included in the plugin. If you would like the list to be pulled from the Google API you will need to define your API key. You can do this in Settings->Google Font Selector in the admin.
For Developers
There are a few more advanced controls you can set to make the plugin do your bidding. If you would like to hard-code the API key and disable users from seeing the nag screen and setting panel you can define the ACFGFS_API_KEY constant.
define( 'ACFGFS_API_KEY', 'your_google_api_key' );

The ACFGFS_REFRESH constant can controls how frequently the plugin checks the Google API for updates. The value is in seconds, 86400 would be a day. The default is set to 7 days.
define( 'ACFGFS_REFRESH', 259200 );

If you would like to disable the automatic enqueueing of fonts you can use the ACFGFS_NOENQUEUE constant. The fonts are only enqueued automatically when this constant is not defined. Define the constant to disable enqueueing.
define( 'ACFGFS_NOENQUEUE', true );

If you want to modify the fonts that are loaded on a page you can use the acfgfs/enqueued_fonts filter. This should return an array of fonts with variants and subsets needed, something like this:
array(
'font' => 'Open Sans',
'variants' => array( 'regular', '700' ),
'subsets' => array( 'latin' )
)

New in 3.0.1 is the ability to control the fonts displayed in the dropdown. If you only want to give your users access to a smaller portion of Google fonts you can use the acfgfs/font_dropdown_array filter to modify the array that is used to generate the dropdown. Please return an array where the key and the value are both the names of the font.
add_filter( 'acfgfs/font_dropdown_array', 'my_font_list' );
function my_font_list( $fonts ) {
$fonts = array(
'Raleway' => 'Raleway',
'Lato' => 'Lato'
);
return $fonts;
}

延伸相關外掛

文章
Filter
Apply Filters
Mastodon