更新日期:2015-03-21

wordpress 內建的文章編輯器是 TinyMce,一般我們在網站上使用這個這編輯器時,只要依據官方給的參數定義值,就可以直接增加或拿掉編輯器的某些功能按鈕,不過在 wordpress 裡面不建議去修改那些檔案,比較好的作法還是利用 hook 方式來做。

以下的步驟,我們要先將『字型』這個功能顯示出來。再來,我們要修改裡面可用的字型種類。

第一步:顯示『字型』功能

(這個步驟,若是裝過 TinyMce advanced 外掛就不用做了)
[php]
add_filter( ‘mce_buttons’ , ‘add_font_selection_to_tinymce’ );
function add_font_selection_to_tinymce($buttons) {
array_push($buttons, ‘fontselect’);
return $buttons;
}
[/php]

第二步:增添可用的字型

[php]
add_filter( ‘tiny_mce_before_init’, ‘use_my_fonts_to_tinymce’ );
function use_my_fonts_to_tinymce( $initArray ) {
$theme_advanced_fonts = ‘黑體=黑體;’;
$theme_advanced_fonts = ‘標楷體=標楷體;’;
$theme_advanced_fonts .= ‘Lato=Lato;’;
$theme_advanced_fonts .= ‘Michroma=Michroma;’;
$initArray[‘font_formats’] = $theme_advanced_fonts;
return $initArray;
}
[/php]

注意:以上有列入的字體,才會在『字型』下拉選單中出現。