首先说下 新版本的编辑器,我觉得十分难受
所以我是换成了旧版再加上多编辑器的
第一步: 安装插件 搜索“经典编辑器” 安装即可
第二步:在functions.php 文件夹里面写入下面代码
/** * 添加一个编辑器字段到文章编辑界面 * https://imtiazrayhan.com/add-wysiwyg-editor-custom-meta-boxes/ */ //This function initializes the meta box. function wpkj_post_editor_meta_box() { add_meta_box ( 'wpkj-post-editor', __('文章顶部内容', 'textdomain') , 'wpkj_post_editor', 'post' // 需要显示编辑框的文章类型,与下文的两处 $_POST['post'] 对应 ); } add_action('admin_init', 'wpkj_post_editor_meta_box'); //Displaying the meta box function wpkj_post_editor($post) { $content = get_post_meta($post->ID, 'wpkj_post_editor', true); //This function adds the WYSIWYG Editor wp_editor ( $content , 'wpkj_post_editor', array ( "media_buttons" => true ) ); } //This function saves the data you put in the meta box function wpkj_post_editor_save_postdata($post_id) { if( isset( $_POST['wpkj_post_editor_nonce'] ) && isset( $_POST['post'] ) ) { //Not save if the user hasn't submitted changes if( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return; } // Verifying whether input is coming from the proper form if ( ! wp_verify_nonce ( $_POST['wpkj_post_editor_nonce'] ) ) { return; } // Making sure the user has permission if( 'post' == $_POST['post'] ) { if( ! current_user_can( 'edit_post', $post_id ) ) { return; } } } $content = get_post_meta($post_id, 'wpkj_post_editor', true); // 如果编辑器中有内容或者之前有数据才保存 if( $content || !empty( $_POST['wpkj_post_editor'] ) ) { $data = $_POST['wpkj_post_editor']; update_post_meta($post_id, 'wpkj_post_editor', $data); } } add_action('save_post', 'wpkj_post_editor_save_postdata');