如何在 Wordpress 元框中添加所见即所得编辑器 [英] How to add wysiwyg editor in Wordpress meta box
本文介绍了如何在 Wordpress 元框中添加所见即所得编辑器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在为我的自定义帖子类型创建一个元框.有多个字段我想使用所见即所得编辑器而不是 .是否可以将多个编辑器添加到元框?
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?
非常感谢您的帮助!
非常感谢.大傻
推荐答案
这里是完整的代码示例:
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. MUST-Recommendation from my experience:
Forget adding custom codes, use Advanced Custom Fields, it's excellent and simplify your life.
这篇关于如何在 Wordpress 元框中添加所见即所得编辑器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文