Reputation: 91
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:
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
Upvotes: 9
Views: 2355
Reputation:
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); ?>");
Upvotes: 0
Reputation: 102
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);
}
});}
Upvotes: 2
Reputation: 133
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.
Upvotes: 0
Reputation: 9331
I know late answer. but it will help others. Try this jQuery plugin.
https://github.com/anteprimorac/js-wp-editor
you can use simple like below
jQuery(document).ready(function (){
jQuery('#container').wp_editor();
});
Upvotes: 3