2017-01-23 74 views
0

我把這段代碼放在我的wordpress function.php中。WordPress中的Tinymce錯誤頁面類別

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 class="form-table"> 
      <tr class="form-field"> 
       <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 class="description"><?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 
    } 
} 

Tinymce你看得很對。

但是應該在「content-html」中顯示的文本顯示在「content-tmce」中。

例如:

"content-html": &lt;strong&gt;hello&lt;/strong&gt; 

"content-tmce": <strong>hello</strong> 

我必須按照本指南:https://paulund.co.uk/add-tinymce-editor-category-description

我該如何解決?

+1

你在哪裏得到這個代碼?它是一個指南嗎?你能鏈接到任何其他資源或例子嗎? –

+0

我遵循這一點:https://paulund.co.uk/add-tinymce-editor-category-description –

+0

你能解釋一下這裏有什麼困擾你嗎?對我來說,它似乎工作正常。我的意思是,它應該很好...... –

回答

2

下面的代碼工作的代碼,它可以幫助你:

add_filter('edit_category_form_fields', 'edit_cat_description'); 

function edit_cat_description($category) { 
    $tag_extra_fields = get_option(description1);?> 
    <table class="form-table"> 
    <tr class="form-field"> 
    <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(html_entity_decode($category->description , ENT_QUOTES, 'UTF-8'), 'description1', $settings); ?> 
    <br /> 
    <span class="description"><?php _e('The description is not prominent by default, however some themes may show it.'); ?></span> 
    </td> 
    </tr> 
    </table> 
    <?php 
} 

add_action('admin_print_styles', 'category_tinymce_css'); 
function category_tinymce_css() { 
?>  
    <style type="text/css"> 
    .quicktags-toolbar input{float:left !important; 
    width:auto !important;} 
    </style> 
    <?php 
} 

add_action('admin_head', 'taxonomy_tinycme_hide_description'); 
function taxonomy_tinycme_hide_description() { 
    global $pagenow; 
    if(($pagenow == 'edit-tags.php' || $pagenow == 'term.php' ||  isset($_GET['action']))) : ?> <script type="text/javascript"> 
    jQuery(function($) { 
    $('#description, textarea#tag-description').closest('.form- field').hide(); 
    }); 
    </script><?php endif; 
} 
+0

這幾乎是正確的,只是我是兩個描述字段。想法? –

+0

意思是你想實現兩個描述字段? –

+0

解決了您的功能:「edit_cat_description」!謝謝:) –

0

你可以在不刪除任何東西的情況下添加任何東西,在現有的textarea上初始化TinyMCE。首先在functions.php排隊管理腳本,我在二十十七

/** 
* Load admin JS scripts 
* 
* @since 1.0.0 
*/ 
function twentyseventeen_scripts_admin() { 
    $js_src = includes_url('js/tinymce/') . 'tinymce.min.js'; 
    $css_src = includes_url('css/') . 'editor.css'; 

    echo '<script src="' . esc_url($js_src) . '" type="text/javascript"></script>'; 

    wp_register_style('tinymce_css', $css_src); 
    wp_enqueue_style('tinymce_css'); 

    wp_enqueue_script('admin', get_theme_file_uri('/assets/js/admin.js'), array('jquery'), '1.0', true); 
} 
add_action('admin_enqueue_scripts', 'twentyseventeen_scripts_admin'); 

其使用的解決方案由myol手動排隊tiny_mce測試。

然後在你admin.js添加

jQuery(document).ready(function($){ 
    "use strict"; 

    if ($('.taxonomy-category').length) { // We're on taxonomy category screen 
     tinyMCE.init({ 
      mode : 'specific_textareas', 
      selector :'#edittag #description, #tag-description' 
     }); 
    } 

}); 

enter image description here

enter image description here

您可以修改TinyMCE的根據自己的喜好(插件等)。

希望這會有所幫助。

相關問題