I'm loading WP_Editor manually through AJAX, but I'm running into some issues with the way I'm loading things.

Firstly, I'm including all the <script> tags into my AJAX callback, which are generated using the following code:

// Create editor so scripts are generated

wp_editor($content, $editor_id, $settings);

$editor = ob_get_contents();


// Get the scripts to return in AJAX call


$scripts = ob_get_contents();


// Return editor HTML and Scripts seperately
wp_send_json_success(array('wp_editor' => $editor, 'scripts' => $scripts));

This returns like 8 <script> tags and 2 CSS files that is inserted into my HTML when the AJAX callback completes. (Note that these are inline JS and urls linking to .js files)

I want to use jQuery's getScript() method to call these scripts instead of inserting <script> tags.

Secondly, on some pages I'm loading more than one WP_Editor, and for each editor I load, the scripts are inserted a second time. This is due to the way I'm calling for all the scripts.

Other than adding extra overhead, this also causes some of the logic inside these JavaScript files to run twice on the same action, a big problem.

Right now, I see a few solutions to the issue I'm facing:

  • Somehow filter which scripts are returned with the code above
  • Intercept the scripts and send them as variables with AJAX
  • Generate the scripts manually (best solution?)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.