WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a theme that is custom developed and really complex. One of the things that I have is multiple content areas where users can specify content for specific tabs. I load multiple instances of the WordPress editor through the wp_editor() function. It works perfectly. (This is all on the admin side, in the "Page" post type)

However, I began making a few improvements, including the ability to add/remove tabs dynamically (before, I loaded 6 editors on the page). Users may have 1-7 tabs.

When users add a tab, it needs to add an instance of the editor to the page. However, no matter what I try, I cannot get it to load and display correctly.

Here are the 2 things that I have tried so far:

  1. Create a php file that has the admin bootstrap included, and then loading the editor with wp_editor(). I then do a jQuery $.load to call the page and include the resulting HTML in the area that it needs to display. This doesn't really work, however, as the editors formatting buttons disappear (it's worth noting, that pulling the page up directly, the editor displays and functions perfectly)
  2. Loaded the editor on the page, inside a hidden div, and then once a tab is added, use jquery to move it into place. This loads the editor in tact, but you cannot use any of the editor buttons (they display, but don't do anything), and you can't put your cursor in the text area (curious, however, that switching to HTML mode allows typing and some interaction with the HTML mode buttons)

So the question is, has anyone had any luck adding editors through AJAX calls? Any advice?

share|improve this question
did you tried to do a ajax call via admin-ajax.php? If no make a function with your code then call it via admin-ajax.php – Sisir May 10 '12 at 15:56
Does this suggestion help? If so, it is not a WordPress question. :) – toscho May 10 '12 at 16:52
@Sisir, If I am reading your suggestion correctly, then it didn't work. I used this to call the Ajax form: $('#sph-tabs-section-tab'+newTab).load('/wp-admin/admin-ajax.php?action=sph_add‌​_editor'); and then added a function that returns wp_editor(). It gets called with no problem, but it still only returns the editor with no buttons. (exact same results as item 1 in the OP) – Aaron Wagner May 10 '12 at 17:44
Once initialized TinyMCE cannot be moved around in DOM. You must remove it, move in DOM and initialize again. Similar code but for frontend comments here on my blog: techytalk.info/… Comments form is moved when user clicks reply/cancel reply. – user20106 Sep 5 '12 at 22:46

To get the quicktags to show up, you need to re instantiate them within your ajax oncomplete handler.

quicktags({id : 'editorcontentid'});

My ajax success handler looks like this;

success: function(data, textStatus, XMLHttpRequest){
            //append editor to dom
            //init quicktags
            quicktags({id : 'editorcontentid'});
            //init tinymce

I've managed to get the editor to load by first calling a static function that creates the editor and caches it as variable. I run the editor creation method on init. This seems to get wordpress to enque all the required scripts.

Its important that when you create your editor instance, that you set it to use tinymce, that way the tinymce js file is enqued as well.

share|improve this answer

You need to call the editor init again once you add your ajax textarea, I did it like this:

$.fn.tinymce_textareas = function(){
    skin : "wp_theme"
    // other options here

Then call your function after your ajax, like this:

share|improve this answer
Please explain how does this work? This does not work. I tried it. – Ahmed Fouad Jul 18 '12 at 18:09
After adding the ajax content which contains the textarea I want tinyMCE on (response), call the tinymce_textareas function which initialises tinyMCE on the new textareas. – shahar Jul 18 '13 at 10:46

The the usable solution from @toscho on github. He build this nice result also for a question here, see his answer for more details.

share|improve this answer
This requires a library for use - T5 ... not a WP-only solution – cale_b Jan 17 '15 at 0:57

Simpler steps:

1) in functions.php,add:

add_action('init','my_wpEditOUPUTT');function my_wpEditOUPUTT(){
    if (isset($_POST['Give_me_editorrr'])){
        wp_editor( '' , 'txtrID_'.$_POST['myNumber'], $settings = array( 'editor_class'=>'my_class',     'textarea_name'=>'named_'. $_POST['myNumber'],  'tinymce'=>true , 'media_buttons' => true , 'teeny' => false,));

2) on HTML page:

<div id="MyPlace"></div> <a href="javascript:myLoad();">Click to load</a>

<script type="text/javascript">
startNumber = 1;
function myLoad(){ alert('wait 1 sec');
    startNumber ++;
    $.post('./index.php', '&Give_me_editorrr=1&myNumber='+startNumber ,
            if (status == "success") {  
                document.getElementById('MyPlace').innerHTML += data; alert("Inserted!");   
                tinymce.init({ selector: 'txtrID_'+startNumber, theme:'modern',  skin:'lightgray'}); tinyMCE.execCommand('mceAddEditor', false, 'txtrID_'+startNumber);
share|improve this answer

After struggling with it, found the solution which works, in a callback after you add new element:

tinymce.execCommand( 'mceAddEditor', true, element.id );

Its strange that there is zero documentation inside codex.

share|improve this answer
tinymce is an external resource, so I think they might think tinymce's own docs cover it - tinymce.com/docs - but pretty poor on examples ... Also you must include tincemce scripts for this answer to work ! (simpliest way is to output one dummy PHP wp_editor() with tinymce arg set to true :-) – jave.web Apr 20 at 20:34

Use this code, hope it will help:

wp_editor( '', 'custom_editor_id' );

More detail can be found here.

share|improve this answer
Please share a gist how this code can help, and then add the link for further details. Link-only answers become invalid if the link is broken - I hope you understand. :) – Mayeenul Islam Apr 15 '15 at 3:34
That link is broken right now and I don't have any context behind the answer. (One of the many reason why "just a link" answers are bad) – Sudar Jul 6 '15 at 16:51

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.