Title: format_for_editor
Published: August 18, 2015
Last modified: February 24, 2026

---

# format_for_editor( string $text, string $default_editor = null ): string

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#description)
    - [See also](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#see-also)
 * [Parameters](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#parameters)
 * [Return](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#return)
 * [Source](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#wp--skip-link--target)

Formats text for the editor.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#description)󠁿

Generally the browsers treat everything inside a textarea as text, but it is still
a good idea to HTML entity encode `<`, `>` and `&` in the content.

The filter [‘format_for_editor’](https://developer.wordpress.org/reference/hooks/format_for_editor/)
is applied here. If `$text` is empty the filter will be applied to an empty string.

### 󠀁[See also](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#see-also)󠁿

 * [_WP_Editors::editor()](https://developer.wordpress.org/reference/classes/_WP_Editors/editor/)

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#parameters)󠁿

 `$text`stringrequired

The text to be formatted.

`$default_editor`stringoptional

The default editor for the current user.
 It is usually either `'html'` or `'tinymce'`.

Default:`null`

## 󠀁[Return](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#return)󠁿

 string The formatted text after filter is applied.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#source)󠁿

    ```php
    function format_for_editor( $text, $default_editor = null ) {
    	if ( $text ) {
    		$text = htmlspecialchars( $text, ENT_NOQUOTES, get_option( 'blog_charset' ) );
    	}

    	/**
    	 * Filters the text after it is formatted for the editor.
    	 *
    	 * @since 4.3.0
    	 *
    	 * @param string $text           The formatted text.
    	 * @param string $default_editor The default editor for the current user.
    	 *                               It is usually either 'html' or 'tinymce'.
    	 */
    	return apply_filters( 'format_for_editor', $text, $default_editor );
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/formatting.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/formatting.php#L4403)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/formatting.php#L4403-L4418)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#hooks)󠁿

 [apply_filters( ‘format_for_editor’, string $text, string $default_editor )](https://developer.wordpress.org/reference/hooks/format_for_editor/)

Filters the text after it is formatted for the editor.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#related)󠁿

| Uses | Description | 
| [apply_filters()](https://developer.wordpress.org/reference/functions/apply_filters/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to a filter hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/format_for_editor/?output_format=md#changelog)󠁿

| Version | Description | 
| [4.3.0](https://developer.wordpress.org/reference/since/4.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2Fformat_for_editor%2F)
before being able to contribute a note or feedback.