在 WordPress 默認情況下,有兩種方法來編輯文章分類,您可以根據他們所屬的標籤或類別來進行編輯。這兩種分類可以自定義名稱,別名和描述。你可以很容易地創建一個分類目錄然後加上一個簡短的説明。 與 WordPress 默認描述字段的問題是,分類裏的編輯器只是簡單的字段文本框。並沒有 TinyMCE 的所見即所得的編輯器,所以你不能把任何額外的樣式或圖像發佈到網站上。在本教程中,就教你如何將 WordPress 分類目錄描述添加上 TinyMCE 編輯器。

用 wp_editor() 函數來添加新的 TinyMCE 框頁面,這個函數可以設置一個默認值來創建 TinyMCE 編輯器框。也可以設置其他的函數:

wp_editor 參數設置 () 。

  • wpautop – 布爾值,自動顯示 WordPress 的周圍添加一個文本段落。
  • media_buttons – 布爾值來顯示多媒體按鍵
  • textarea_name – 表格上的文本域的名稱,這個值是在提交表單時通過。
  • textarea_rows – 行文本區域顯示的數目
  • 的 tabIndex – 在表單字段中使用的的 tabindex
  • editor_css – 這是 TinyMCE 的額外的 CSS 樣式
  • editor_class – 額外的 CSS 類添加到 TinyMCE 的編輯器
  • TinyMCE 的 – 可用於直接傳遞設置在 TinyMCE
  • quicktags – 轉至其他設置的 quicktags

添加 edit_category_form_field 函數過濾分類,輸出一個新表。。

add_filter('edit_category_form_fields', 'cat_description');
function cat_description($tag)
{
?>
<table >
<tr >
<th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
<td>
<?php
$settings = array('wpautop' => true, 'media_buttons' => true, 'quicktags' => true, 'textarea_rows' => '15', 'textarea_name' => 'description' );
wp_editor(wp_kses_post($tag->description , ENT_QUOTES, 'UTF-8'), 'cat_description', $settings);
?>
<br />
<span ><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></span>
</td>
</tr>
</table>
<?php
}

刪除默認的描述文本框:

add_action('admin_head', 'remove_default_category_description');
function remove_default_category_description()
{
global $current_screen;
if ( $current_screen->id == 'edit-category' )
{
?>
<script type="text/javascript">
jQuery(function($) {
$('textarea#description').closest('tr.form-field').remove();
});
</script>
<?php
}
}

刪除 HTML 過濾器元素再保存的完整插件代碼:

// remove the html filtering
remove_filter( 'pre_term_description', 'wp_filter_kses' );
remove_filter( 'term_description', 'wp_kses_data' );
add_filter('edit_category_form_fields', 'cat_description');
function cat_description($tag)
{
?>
<table >
<tr >
<th scope="row" valign="top"><label for="description"><?php _ex('Description', 'Taxonomy Description'); ?></label></th>
<td>
<?php
$settings = array('wpautop' => true, 'media_buttons' => true, 'quicktags' => true, 'textarea_rows' => '15', 'textarea_name' => 'description' );
wp_editor(wp_kses_post($tag->description , ENT_QUOTES, 'UTF-8'), 'cat_description', $settings);
?>
<br />
<span ><?php _e('The description is not prominent by default; however, some themes may show it.'); ?></span>
</td>
</tr>
</table>
<?php
}

add_action('admin_head', 'remove_default_category_description');
function remove_default_category_description()
{
global $current_screen;
if ( $current_screen->id == 'edit-category' )
{
?>
<script type="text/javascript">
jQuery(function($) {
$('textarea#description').closest('tr.form-field').remove();
});
</script>
<?php
}
}
?>