This function renders an editor in a page in the typical fashion used in Posts and Pages.

wp_editor() 描述


 <?php wp_editor$content$editor_id$settings = array() ); ?> 

wp_editor() 用法



(string) (必填) Initial content for the editor.

默认值: None


(string) (必填) HTML id attribute value for the textarea and TinyMCE. (may only contain lowercase letters and underscores...hyphens will cause editor to not display properly)

默认值: None


(array) (可选) An array of arguments.

默认值: array()



(boolean) (可选) Whether to use wpautop for adding in paragraphs. Note that the paragraphs are added automatically when wpautop is false.

默认值: true


(boolean) (可选) Whether to display media insert/upload buttons

默认值: true


(string) (可选) The name assigned to the generated textarea and passed parameter when the form is submitted. (may include [] to pass data as array)

默认值: $editor_id


(integer) (可选) The number of rows to display for the textarea

默认值: get_option('default_post_edit_rows', 10)


(integer) (可选) The tabindex value used for the form field

默认值: None


(string) (可选) Additional CSS styling applied for both visual and HTML editors buttons, needs to include <style> tags, can use "scoped"

默认值: None


(string) (可选) Any extra CSS Classes to append to the Editor textarea

默认值: Empty string


(integer) (可选) The height to set the editor in pixels. If set, will be used instead of textarea_rows. (since WordPress 3.5)

默认值: None


(boolean) (可选) Whether to output the minimal editor configuration used in PressThis

默认值: false


(boolean) (可选) Whether to replace the default fullscreen editor with DFW (needs specific DOM elements and CSS)

默认值: false


(array) (可选) Load TinyMCE, can be used to pass settings directly to TinyMCE using an array

默认值: true


(array) (可选) Load Quicktags, can be used to pass settings directly to Quicktags using an array. Set to false to remove your editor's Visual and Text tabs.

默认值: true


(boolean) (可选) Enable Drag & Drop Upload Support (since WordPress 3.9)

默认值: false

wp_editor() 参数


This function does not return a value.

wp_editor() 返回值


Display an empty editor using the default settings:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */


$content = '';
$editor_id = 'mycustomeditor';

wp_editor( $content, $editor_id );


Fill an editor with the content for a particular post:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */


$post_id = 51;
$post = get_post( $post_id, OBJECT, 'edit' );

$content = $post->post_content;
$editor_id = 'editpost';

wp_editor( $content, $editor_id );


We can also pass an array of one or more settings if the defaults don't suit our needs. For example, if we wanted to hide the insert media buttons, we would do this:

/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */


$settings = array( 'media_buttons' => false );

wp_editor( $content, $editor_id, $settings );


wp_editor() 示例


  • Note that the ID that is passed to the wp_editor() function can only be composed of lower-case letters. No underscores, no hyphens. Anything else will cause the WYSIWYG editor to malfunction. (As of 3.6.1 you can use underscores in the ID.)
  • Once instantiated, the WYSIWYG editor cannot be moved around in the DOM. What this means in practical terms, is that you cannot put it in meta-boxes that can be dragged and placed elsewhere on the page. Instead use 'edit_page_form' (for pages) or 'edit_form_advanced' (for other post types):
/* ----------------------------------
 * wordpress之魂 © http://wphun.com
 * ---------------------------------- */

add_action( 'edit_page_form', 'my_second_editor' );
function my_second_editor() {
	// get and set $content somehow...
	wp_editor( $content, 'mysecondeditor' );

wp_editor() 注意


  • 添加于 版本 3.3

wp_editor() 历史