wp_editor( string $content, string $editor_id, array $settings = array() )

Renders an editor.


Description

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.

Top ↑

See also


Top ↑

Parameters

$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 Optional
See _WP_Editors::parse_settings() for description.
More Arguments from _WP_Editors::parse_settings( ... $settings ) Array of editor arguments.
  • wpautop bool
    Whether to use wpautop() . Default true.
  • media_buttons bool
    Whether to show the Add Media/other media buttons.
  • default_editor string
    When both TinyMCE and Quicktags are used, set which editor is shown on page load. Default empty.
  • drag_drop_upload bool
    Whether to enable drag & drop on the editor uploading. Default false.
    Requires the media modal.
  • textarea_name string
    Give the textarea a unique name here. Square brackets can be used here. Default $editor_id.
  • textarea_rows int
    Number rows in the editor textarea. Default 20.
  • tabindex string|int
    Tabindex value to use. Default empty.
  • tabfocus_elements string
    The previous and next element ID to move the focus to when pressing the Tab key in TinyMCE. Default ':prev,:next'.
  • editor_css string
    Intended for extra styles for both Visual and Text editors.
    Should include <style> tags, and can use "scoped". Default empty.
  • editor_class string
    Extra classes to add to the editor textarea element. Default empty.
  • teeny bool
    Whether to output the minimal editor config. Examples include Press This and the Comment editor. Default false.
  • dfw bool
    Deprecated in 4.1. Unused.
  • tinymce bool|array
    Whether to load TinyMCE. Can be used to pass settings directly to TinyMCE using an array. Default true.
  • quicktags bool|array
    Whether to load Quicktags. Can be used to pass settings directly to Quicktags using an array. Default true.

Default: array()


Top ↑

Source

File: wp-includes/general-template.php. View all references

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 );
}


Top ↑

Changelog

Changelog
Version Description
3.3.0 Introduced.

Top ↑

User Contributed Notes

  1. Skip to note 1 content
    Contributed by M A Vinoth Kumar

    Get the wp_editor through AJAX Call,

    add_action( 'wp_ajax_bc_ajax_request', 'bc_ajax_request_fn' ); 
    function bc_ajax_request_fn(){
    $html ='';
    $html .= bc_get_wp_editor('Test Message','primary_editor',array());
    return $html;
    }
    function bc_get_wp_editor( $content = '', $editor_id, $options = array() ) {
    	ob_start();
    
    	wp_editor( $content, $editor_id, $options );
    
    	$temp = ob_get_clean();
    	$temp .= \_WP_Editors::enqueue_scripts();
    	$temp .= print_footer_scripts();
    	$temp .= \_WP_Editors::editor_js();
    
    	return $temp;
    }
  2. Skip to note 2 content
    Contributed by Mário Valney

    To edit tinymce Visual Buttons, you should use toolbar instead of TinyMCE documentation’s theme_advanced_buttons attribute:

    $args = array(
        'tinymce'       => array(
            'toolbar1'      => 'bold,italic,underline,separator,alignleft,aligncenter,alignright,separator,link,unlink,undo,redo',
            'toolbar2'      => '',
            'toolbar3'      => '',
        ),
    );
    wp_editor( $content, $editor_id, $args );
  3. Skip to note 4 content
    Contributed by Codex

    Modify the editor’s default settings when initializing it
    You can pass an array of one or more settings to modify for this editor instance, such as hiding the insert media buttons.

    $content   = '';
    $editor_id = 'mycustomeditor';
    $settings  = array( 'media_buttons' => false );
    
    wp_editor( $content, $editor_id, $settings );
  4. Skip to note 7 content
    Contributed by Mustafa BOŞNAK

    Remove HTML button and media button in editor. Create blank content. Define a custom name and id for the editor. Determine your editor’s row count.

    $content = "";
    $custom_editor_id = "editorid";
    $custom_editor_name = "editorname";
    $args = array(
    		'media_buttons' => false, // This setting removes the media button.
    		'textarea_name' => $custom_editor_name, // Set custom name.
    		'textarea_rows' => get_option('default_post_edit_rows', 10), //Determine the number of rows.
    		'quicktags' => false, // Remove view as HTML button.
    	);
    wp_editor( $content, $custom_editor_id, $args );

You must log in before being able to contribute a note or feedback.