如何在Wordpress meta框中添加所见即所得的编辑器 [英] How to add wysiwyg editor in Wordpress meta box

查看:107
本文介绍了如何在Wordpress meta框中添加所见即所得的编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为我的自定义帖子类型创建一个meta框。我想在多个字段中使用wysiwyg编辑器,而不是< textarea>

I'm creating a meta box for my custom post type. There are multiple fields where I would like to use wysiwyg editor rather than <textarea>. Is is possible to add multiple editors to a meta box?

非常感谢您的帮助!

很多谢谢。
Dasha

Many thanks. Dasha

推荐答案

下面是完整的代码示例:

Here is full code example:

add_action( 'add_meta_boxes',  function() { 
    add_meta_box('html_myid_61_section', 'TITLEEEEE', 'my_output_function');
});

function my_output_function( $post ) {
    $text= get_post_meta($post, 'SMTH_METANAME' , true );
    wp_editor( htmlspecialchars($text), 'mettaabox_ID', $settings = array('textarea_name'=>'MyInputNAME') );
}

add_action( 'save_post', function($post_id) {
    if (!empty($_POST['MyInputNAME'])) {
        $datta=sanitize_text_field($_POST['MyInputNAME']);
        update_post_meta($post_id, 'SMTH_METANAME', $datta );
    }
}); 



P.S。根据我的经验必须推荐:



忘记添加自定义代码,请使用 高级自定义字段 ,它非常好,可以简化您的生活。

P.S. MUST-Recommendation from my experience:

Forget adding custom codes, use Advanced Custom Fields, it's excellent and simplify your life.

这篇关于如何在Wordpress meta框中添加所见即所得的编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆