在 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
}
}
?>