Wordpress中的Tinymce错误页面类别

时间:2017-01-23 15:22:27

标签: php jquery html wordpress tinymce

我把这段代码放在我的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
    }
}

你看得正确。

但应该在&#34; content-html&#34;中显示的文字。显示在&#34; content-tmce&#34;。

例如:

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

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

我已遵循本指南:https://paulund.co.uk/add-tinymce-editor-category-description

我该如何解决?

2 个答案:

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

答案 1 :(得分:0)

您可以在不删除任何内容的情况下添加任何内容,在现有的textarea上初始化TinyMCE。首先在functions.php排队管理脚本中,我在Twenty Seventeen上进行了测试

/**
 * 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(插件等)。

希望这有帮助。