<?php wp_editor( $content, $editor_id, $settings = array() ); ?>
参数说明
$content (string) (required) 编辑器的初始内容。 Default: None $editor_id (string) (required) 文本区域和tinymce的html id属性值。只能包含小写字母和下划线。连字符会导致编辑器显示不正确。 Default: None $settings (array) (optional) 参数数组。 Default: array() Argumentswpautop (boolean) (optional) 是否使用wpautop添加段落。请注意,当wpautop为false时,将自动添加段落。 Default: true media_buttons (boolean) (optional) 是否显示媒体插入/上载按钮 Default: true textarea_name (string) (optional) 提交表单时分配给生成的文本区域和传递参数的名称。可以包含[]以将数据作为数组传递。) Default: $editor_id textarea_rows (integer) (optional) 为文本区域显示的行数 Default: get_option('default_post_edit_rows', 10) tabindex (integer) (optional) 用于窗体字段的TabIndex值 Default: None editor_css (string) (optional) 附加的CSS样式应用于视觉和HTML编辑器按钮,需要包括<style>标记,可以使用“范围” Default: None editor_class (string) (optional) 附加到编辑器文本区域的任何额外CSS类 Default: Empty string editor_height (integer) (optional) 以像素为单位设置编辑器的高度。如果设置,将使用而不是文本区域\行。(从WordPress 3.5开始) Default: None teeny (boolean) (optional) 是否输出PressThis中使用的最小编辑器配置 Default: false dfw (boolean) (optional) 无论是默认的全屏编辑器与DFW replace。CSS和DOM元素的空间特异性。 Default: false tinymce (array) (optional) 加载tinymce,可用于使用数组将设置直接传递给tinymce Default: true quicktags (array) (optional) 加载快速标记,可用于使用数组将设置直接传递给快速标记。设置为false可删除编辑器的视觉和文本选项卡。 Default: true drag_drop_upload (boolean) (optional) 启用拖放上载支持(从WordPress 3.9开始) Default: false
参数说明
使用默认设置显示空编辑器:
<?php $content = ''; $editor_id = 'mycustomeditor'; wp_editor( $content, $editor_id ); ?>
用特定文章的内容填充编辑器:
<?php $post_id = 51; $post = get_post( $post_id, OBJECT, 'edit' ); $content = $post->post_content; $editor_id = 'editpost'; wp_editor( $content, $editor_id ); ?>
如果默认值不适合我们的需要,我们还可以传递一个或多个设置的数组。例如,如果我们想隐藏“插入媒体”按钮,我们可以这样做:
<?php $settings = array( 'media_buttons' => false ); wp_editor( $content, $editor_id, $settings ); ?>
我们还可以使用自定义按钮列表(包括自定义快速标记列表)修改默认的快速标记。
<?php $settings = array( 'quicktags' => array( 'buttons' => 'strong,em,del,ul,ol,li,close' ), // note that spaces in this list seem to cause an issue ); wp_editor( $content, $editor_id, $settings ); ?>
请注意,传递给wp_editor()函数的ID只能由小写字母组成。没有下划线,没有连字符。其他任何事情都会导致WYSIWYG编辑器出现故障。(从3.6.1开始,您可以在ID中使用下划线。)
一旦实例化,所见即所得编辑器就不能在DOM中移动。从实际意义上讲,这意味着你不能把它放在元框中,而元框可以被拖放到页面的其他地方。相反,使用“编辑页面”或“编辑表单”高级(对于其他帖子类型):
add_action( 'edit_page_form', 'my_second_editor' ); function my_second_editor() { // get and set $content somehow... wp_editor( $content, 'mysecondeditor' ); }