wp_editor()WP 3.3.0

Renders an editor. Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.

NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used. On the post edit screen several actions can be used to include additional editors containing TinyMCE: 'edit_page_form', 'edit_form_advanced' and 'dbx_post_sidebar'. See https://core.trac.wordpress.org/ticket/19173 for more information.

Using this function is the proper way to output all needed components for both TinyMCE and Quicktags. _WP_Editors should not be used directly. See https://core.trac.wordpress.org/ticket/17144.

NOTE: Once initialized the TinyMCE editor cannot be safely moved in the DOM. For that reason running wp_editor() inside of a meta box is not a good idea unless only Quicktags is used. On the post edit screen several actions can be used to include additional editors containing TinyMCE: edit_page_form, edit_form_advanced dbx_post_sidebar. See https://core.trac.wordpress.org/ticket/19173 for more information.

No Hooks.

Return

null. Nothing.

Usage

wp_editor( $content, $editor_id, $settings );
$content(string) (required)
Initial content for the editor.
$editor_id(string) (required)
HTML ID attribute value for the textarea and TinyMCE. Should not contain square brackets.
$settings(array)
See _WP_Editors::parse_settings() for description.
Default: array()

Examples

0

#1 TinyMCE on the pages of the site

Let's display the text input field with the TinyMCE editor and HTML editor somewhere on the pages of the site.

To do this, insert the following code in the template file, in the place where you want to display such a field:

<?php wp_editor( '', 'wpeditor', [ 'textarea_name' => 'content' ] ); ?>
0

#2 Let's fill in the field with the content of post 51:

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

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

wp_editor( $content, $editor_id );
0

#3 Changing form settings

We can also change the output form settings if we don't like the basic ones. For example, we can remove the add media button:

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

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

Notes

Changelog

Since 3.3.0 Introduced.

Code of wp_editor() WP 5.9.3

function wp_editor( $content, $editor_id, $settings = array() ) {
	if ( ! class_exists( '_WP_Editors', false ) ) {
		require ABSPATH . WPINC . '/class-wp-editor.php';
	}
	_WP_Editors::editor( $content, $editor_id, $settings );
}