How to load wp_editor using Jquery?

I want to add WordPress editor dynamically using jquery in my custom plugin as follow:

 <?php

  $content = '';

  $editor_id = 'mycustomeditor';      

?>

 $('#container').append('<?php wp_editor( $content, $editor_id );?>');

I am getting error:

Read More

SyntaxError: missing ) after argument list

...-active"><link rel='stylesheet' id='editor-buttons-css'  href='http://localhost 

I have also tried bellow code(here I have replaced single quotes to double quotes):

  <?php

     $content = '';

     $editor_id = 'mycustomeditor';      

  ?>

  $('#container').append("<?php wp_editor( $content, $editor_id );?>");

I am getting error:

 SyntaxError: missing ) after argument list   


$('#container').append("<div id="wp-mycustomeditor-wrap" class="wp-core-ui wp-ed...

If you have any solution please let me know.

Thanks in advance

Related posts

Leave a Reply

4 comments

  1.    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,));
        exit;   
    }}
    
    <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 ,
        function(data,status){ 
            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);
            }
    });}
    

  2. I think the problem is you are using single inverted comma here:

    '<?php wp_editor( $content, $editor_id );?>'

    and here:

       $content = '';
       $editor_id = 'mycustomeditor';
    

    Try with double inverted commas, and see if that helps.

  3. you nee comment internal char (“) and change wp_ by the_ to get string.

    in php:

    $editorCode = the_editor( $content, $editor_id );
    

    in script replace:

    $('#container').append("<?php echo str_replace('"', '"', $editorCode); ?>");