Wordpress 中的 Tinymce 错误页面类别

Tinymce error page category in Wordpress

我把这段代码放在我的wordpress里function.php.

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

我该如何解决?

您可以在不删除任何内容并添加任何内容的情况下在现有文本区域上初始化 TinyMCE。首先在 functions.php 排队管理脚本中,我在 2017

上进行了测试
/**
 * 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'
        });
    }

});

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

希望对您有所帮助。

以下代码是工作代码,它可能对您有所帮助:

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;
 }