Quick Tip: Using wp_editor

In this tip we will find out what wp_editor is good for!


What Is wp_editor?

Text editor / notepad icon

It is a WordPress function that creates a visual (WYSIWYG) editor like the one featured in the WordPress admin when creating posts or pages. This handy little function has been available since WordPress v3.3.
There is a detailed Codex page about wp_editor, if you need more information. WordPress uses a custom version of TinyMCE editor, which can be found here. To check out the files please see wp-includes/js/tinymce in your WordPress install's directory.

The editor window in WordPress admin interface
The usual editor in the admin

Why We Need This?

Because we can use this feature in themes and plugins as well! Rich content comes in handy on several occasions, not just in posts. We can use multiple editors on a single subpage, just use the content and ID variables appropriately.


Examples

Code icon

This part assumes you know at least some basic PHP programming. The $content and $editor_id variables are mandatory, they must be set at all times. The $settings variable is an array in which the single editor features can be switched on / off.

Please note that most of the explainations are in the comments, read them as well!

The following codes (1, 2, 3 and 4) show how to use the function.


Customizing the Editor

Cog icon

We can customize the editor features with the help of this description in the Codex. For digging deeper you can also check out class-wp-editor.php under wp-includes in your WordPress install.

Tags:

Comments

Related Articles