I'm trying to add additional wp_editor
instances when a user clicks an "Add content" button in the back-end. I have it mostly working, except that the user needs to save the post after adding the field in order for the TinyMCE editor to appear, as it's initialized with the PHP wp_editor()
function.
After some digging, I found the wp.editor.initialize()
(docs) JavaScript function, which seems like it should initialize a new editor given a textarea's ID.
This doesn't seem to work, no matter what I try. I have the following code:
<textarea id="custom-tinymce-testing" name="custom-tinymce-testing"></textarea>
Which I try to initialize with JavaScript after clicking a button:
wp.editor.initialize("custom-tinymce-testing", {
mediaButtons: true,
tinymce: true,
quicktags: true,
});
This doesn't appear to do anything; the textarea remains unchanged, and no console errors are thrown. Running console.log(wp.editor.initialize())
does show that the function exists, so I don't think it's an ordering thing.
What am I doing wrong here?