wp_editor( string $content, string $editor_id, array $settings = array() )
Renders an editor.
Contents
Description 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.
See also See also
Parameters Parameters
- $content
-
(string) (Required) Initial content for the editor.
- $editor_id
-
(string) (Required) HTML ID attribute value for the textarea and TinyMCE. Can only be /[a-z]+/.
- $settings
-
(array) (Optional) See _WP_Editors::editor().
Default value: array()
Source Source
File: wp-includes/general-template.php
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 );
}
Expand full source code Collapse full source code View on Trac
Changelog Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |
User Contributed Notes User Contributed Notes
You must log in before being able to contribute a note or feedback.
Display an empty editor using the default settings
The $settings array is actually described on the [_WP_Editors::parse_settings()](https://developer.wordpress.org/reference/classes/_wp_editors/parse_settings/) method
Fill an editor with the content for a particular post
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.
To edit tinymce Visual Buttons, you should use
toolbarinstead of TinyMCE documentation’stheme_advanced_buttonsattribute:$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 );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; }