I’m a novice and looking to add the wp_editor to a custom metabox textarea field. I’ve looked seemingly everywhere for an complete example for writing a metabox with a textarea that uses the wp_editor. I am looking for a complete beginning to end example.
I do not want to use a plugin.
Anyone have a link to a complete example?
Thanks
There is at least 1 issue with using wp_editor in a meta box, as discussed in ticket #19173(Good read on the subject of wp_editor and meta boxes). TinyMCE gets all messed up if you move the meta box that contains it (specifically, if TinyMCE’s location in the DOM is changed). You can, however, use the Quicktags version (non tinyMCE). Another alternative is to just not move the box (lame) or add your editors using the
edit_page_form
oredit_form_advanced
hooks instead of usingadd_meta_box()
.I wrote a quick plugin to demonstrate the issue. It’s a fully working example of using wp_editor in a meta box though. You can configure wp_editor to make it more meta box friendly by disabling TinyMCE and enabling quicktags using the appropriate args.
Edit: This version of the wp_editor_meta_box() function from the example above, will have TMCE disabled, and Quicktags enabled:
Are you looking for a code example from scratch, or would you consider integrating a custom metabox plugin which supports a WYSIWYG editor in a metabox? If the latter, might I suggest https://github.com/jaredatch/Custom-Metaboxes-and-Fields-for-WordPress