WordPress把分类描述改为图文富文本编辑器

追格官方小助手/ 2022年06月06日/ WordPress/ 浏览 1309

WordPress分类的描述是一个 textarea ,只支持纯文本信息。


怎样才能把 textarea 变成一个 富文本编辑器呢?


其实,还是要用到为分类添加属性的钩子 category_edit_form_fields 和 category_add_form_fields 。先利用这两个钩子,添加一个和原来textarea表单名称一样的富文本编辑器。然后,再把之前的textarea删掉。


参考代码如下:


add_action("category_edit_form_fields", 'edit_form_fields_example', 10, 2);
add_action("category_add_form_fields", 'add_form_fields_example', 10, 2);
function edit_form_fields_example($term){
    ?>
    <tr valign="top">
        <th scope="row"><?php _e('描述','salong'); ?></th>
        <td>
            <?php wp_editor(html_entity_decode($term->description), 'description', array('media_buttons' => true,'quicktags'=>true)); ?>
            <script>
                // 删除原来的textarea
                jQuery(window).ready(function(){
                    jQuery('label[for=description]').parent().parent().remove();
                });
            </script>
        </td>
    </tr>
    <?php
}

function add_form_fields_example(){
    ?>
    <tr valign="top">
        <th scope="row"><?php _e('描述','salong'); ?></th>
        <td>
            <?php wp_editor('', 'description', array('media_buttons' => true,'quicktags'=>true)); ?>
            <script>
                // 删除原来的textarea
                jQuery(window).ready(function(){
                    jQuery('label[for=tag-description]').parent().remove();
                });
            </script>
        </td>
    </tr>
    <?php
}


发表评论

暂无评论,抢个沙发...

客服 工单