內容簡介
這款外掛可以在 Gutenberg 區塊編輯器中的段落、標題、清單或按鈕等豐富文字區塊中添加內嵌圖示。該外掛以免費的 Font Awesome 圖示集作為預設圖示集。您可以在版本 4.x、5.x 和版本 6.x 之間進行選擇。
此外掛還提供了一個易於使用的介面,可基於 SVG 圖示創建自定義圖示集。可以使用簡單易用的拖放上傳器從外掛設置中上傳自定義圖示。
此外,外掛還為 Advanced Custom Fields (ACF) 創建了一種新的字段類型:JVM 圖示字段。現在,您可以創建與 Font Awesome 圖示集或甚至更好的自定義圖示集配合使用的自定義字段。
如果 Font Awesome 或內置的自定義圖示集配置器不滿足您的需求,您也可以創建自己的自定義圖示集並使用外掛提供的 Hooks 加載它。
外掛只是以以下 HTML 格式插入圖示:
<i class="icon fa fa-address-book" aria-hidden="true"> </i>
如果您準備為 WordPress 主題編寫一些 PHP Hooks,則可以將 CSS 類名和可用圖示全部進行修改,但請注意,您應將外掛設置保持為使用「Font Awesome 4.7」。
如果您想加載自己製作的自定義網頁字體或圖示集,請繼續閱讀。您可以通過從外掛設置中設置為「自定義 SVG 圖示集」並從外掛設置中上傳 SVG 文件來實現此目的。
CSS 文件
默認情況下,前端和後端都會加載 Font Awesome 4.7 的略微自定義版本的 CSS 文件,以便使外掛能夠直接運行,但您也可以從設置屏幕中選擇 Font Awesome Free 版本 5.x 或 6.x。
如果您想使用自己製作的圖示集,建議您使用外掛提供的 Hooks 覆蓋圖示集 json 文件和 CSS 文件。
自定義圖示集文件
如果外掛設置為 Font Awesome 4.7 圖示集(預設行為),則圖示將從 wp-content/plugins/jvm-richtext-insert-icons/dist/fa-4.7/icons.json 加載。json 文件包含所有可由 Font Awesome 4.7 CSS 文件轉換為圖示的 css 類。您可以在 (子)主題 functions.php 中調用過濾器呼叫自定義 json 圖示集文件。
例如:
function add_my_icons($file) {
$file = get_stylesheet_directory() .'/path_to_my/icons.json';
return $file;
}
add_filter( 'jvm_richtext_icons_iconset_file', 'add_my_icons');
自從版本 1.0.3 起,圖示配置文件也可以是 fontello 格式。請參閱:https://fontello.com以創建您的自定義圖示集。
自定義 CSS 文件
默認情況下,外掛會從 wp-content/plugins/jvm-richtext-insert-icons/dist/fa-4.7/font-awesome.min.css 加載 Font Awesome 4.7 CSS。您可以在 (子) 主題 functions.php 中調用過濾器呼叫自定義 CSS 文件以供您的圖示集使用。
例如:
function add_my_css($cssfile) {
$cssfile = get_stylesheet_directory_uri() .'/path_to_my/cssfile.css';
return $cssfile;
}
add_filter( 'jvm_richtext_icons_css_file', 'add_my_css');
如果您選擇加載自己的 CSS 文件並想要禁用默認 CSS 文件,請使用以下代碼:
add_filter( 'jvm_richtext_icons_css_file', '__return_false');
所有圖示標記都在插入圖示時添加了 classname「icon」。如果您想使用其他前綴,可以添加過濾器。例如:
function my_icon_class($css_class_name) {
return 'my-custom-css-class-name';
}
add_filter( 'jvm_richtext_icons_classname', 'my_icon_class');
外掛標籤
開發者團隊
原文外掛簡介
Add icons to any rich text field in the WordPress block editor. Insert icons inline in paragraphs, headings, lists, buttons, or use the dedicated single icon block.
Features
Icon picker – Select icons from a searchable popup in the block editor toolbar.
Font Awesome included – Ships with Font Awesome 4.7, 5.x and 6.x. Choose your preferred version from the settings.
Custom SVG icon set – Upload your own SVG icons via a drag & drop uploader in the plugin settings. This is the recommended approach for the best performance.
Single icon block – A dedicated block with font size, color, alignment and spacing options.
ACF integration – Adds a “JVM Icon” field type for Advanced Custom Fields.
See it in action
How it works
Pick an icon from the toolbar while editing any rich text field. The plugin inserts a small HTML tag that gets styled by the chosen icon set.
Why use a custom SVG icon set?
When you use a custom SVG icon set, the plugin defaults to inline SVG rendering. This is a great choice for performance! Google PageSpeed Insights will thank you.
Better page speed – No render-blocking CSS or font files to download. Icons are part of the HTML itself.
Only loads what you use – Unlike Font Awesome which loads CSS for hundreds of icons, inline SVG only includes the icons that are actually on the page.
No external requests – Everything is served inline, so there are no extra HTTP requests for font or CSS files.
Inherits text color – Icons automatically use the surrounding text color, no extra CSS needed.
Fully reversible – The stored content in the database is not modified. You can switch between render technologies at any time from the plugin settings if you want to.
Alternative render technologies (CSS masks, ::before / ::after pseudo-elements) are also available for custom SVG icons if your use case requires it.
For developers
The plugin provides several filter hooks to customize its behavior. You can load your own icon set, CSS file, or change the icon class prefix.
Load a custom icon set file
add_filter( 'jvm_richtext_icons_iconset_file', function($file) {
return get_stylesheet_directory() . '/path_to_my/icons.json';
});
Load a custom CSS file
add_filter( 'jvm_richtext_icons_css_file', function($cssfile) {
return get_stylesheet_directory_uri() . '/path_to_my/cssfile.css';
});
To disable the default CSS file entirely:
add_filter( 'jvm_richtext_icons_css_file', '__return_false');
Change the icon class prefix
add_filter( 'jvm_richtext_icons_base_class', function() {
return 'my-custom-css-class-name';
});
Disable the settings screen
add_filter( 'jvm_richtext_icons_show_settings', '__return_false');
Please note that if you are loading a custom icon set with the plugin hook: jvm_richtext_icons_css_file, you should make sure the plugin is not set to My SVG uploads as this setting does not load any CSS file.
