the_editor_contentfilter-hookWP 2.1.0

Sets preliminary content/text for the WordPress editor — the default text.

For example, this filter can set the initial content for a post type when a new post is created.

There is also a similar default_content hook that sets default content for the post being created rather than for the editor. It fires whenever a post is published, including through press-this, XML-RPC, and so on. The two hooks are interchangeable in 80% of cases.

There are also similar hooks:

  • for the title — default_title
  • for the excerpt — default_excerpt.

Usage

add_filter( 'the_editor_content', 'wp_kama_the_editor_content_filter', 10, 2 );

/**
 * Function for `the_editor_content` filter-hook.
 * 
 * @param string $content        Default editor content.
 * @param string $default_editor The default editor for the current user. Either 'html' or 'tinymce'.
 *
 * @return string
 */
function wp_kama_the_editor_content_filter( $content, $default_editor ){

	// filter...
	return $content;
}

Parameters

$content(string)
The content that will be placed in the WordPress editor.

Examples

#1 Set initial content for the xxx post type

add_filter('the_editor_content', 'new_xxx_content');
function new_xxx_content( $content ){
	global $post;

	// Set text only if there is no content yet and this is the required post type
	if( empty( $content ) && $post->post_type == 'xxx' ){
		return 'This is the initial text for the post.';
	}

	return $content;
}

#2 Set default content through the 'default_content' hook

add_filter( 'default_content', 'custom_post_type_content' );
function custom_post_type_content( $content ) {
	if( function_exists('get_current_screen') && get_current_screen()->post_type == 'my_post') {
		$content = 'Default content for posts of the "my_post" type';
		return $content;
	}
}

Changelog

Since 2.1.0 Introduced.

Where the hook is called

_WP_Editors::editor()
the_editor_content
WP_Widget_Text::form()
the_editor_content
wp-includes/class-wp-editor.php 289
$content = apply_filters( 'the_editor_content', $content, $default_editor );
wp-includes/widgets/class-wp-widget-text.php 474
$text = apply_filters( 'the_editor_content', $instance['text'], $default_editor );

Where the hook is used in WordPress

wp-includes/class-wp-editor.php 277
add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
wp-includes/class-wp-editor.php 293
remove_filter( 'the_editor_content', 'format_for_editor' );
wp-includes/widgets/class-wp-widget-text.php 467
add_filter( 'the_editor_content', 'format_for_editor', 10, 2 );
wp-includes/widgets/class-wp-widget-text.php 478
remove_filter( 'the_editor_content', 'format_for_editor' );