How To Add the “Add Media” Button When Using wp.editor.initialize()
This is just a quick note for anyone who runs into the same issue. If you use wp.editor.initialize()
to dynamically create an instance of the WordPress visual editor, the editor will be missing the “Add Media” button by default. To fix that, you need to do two things:
1. Add mediaButtons: true
to the setting object that you pass to the function:
wp.editor.initialize('textarea-id', { tinymce: { /* ... */ }, quicktags: true, mediaButtons: true // <--- });
2. Call wp_enqueue_media()
somewhere, like from the admin_enqueue_scripts hook.
This should make the “Add Media” button appear above the editor.
Related posts :