0
votes

I'm creating a repeatable meta box using this code below. how can i add a wysiwyg editor in this textarea field . any help is very much appreciated

How to create meta box using clone ajax and jquery in wordpress

Thanks

3

3 Answers

2
votes

It is an old question but maybe someone else might need it, so here is how you do it:

<textarea id="tag-description"></textarea>

First let the document load, then check if tinyMCE present and initialize the editor.

jQuery(document).ready(function() {
    if ( typeof( tinyMCE ) == "object") {
        tinyMCE.init({
            selector: '#tag-description'
        });
    }
});
0
votes

Add the class 'theEditor' to your textarea.

<textarea class=”theEditor” name=’blurb’ id=’blurb’></textarea>

Edit:

You can also add editor with js

    <script type="text/javascript">
jQuery(document).ready(function() {
    jQuery("#blurb").addClass("mceEditor");
    if ( typeof( tinyMCE ) == "object" &&
         typeof( tinyMCE.execCommand ) == "function" ) {
        tinyMCE.execCommand("mceAddControl", false, "blurb");
    }
});
</script>

<textarea class="" name='blurb' id='blurb'></textarea>
0
votes

Perhaps you're using a more recent version of tinyMCE. Change

tinyMCE.execCommand("mceAddControl", false, "blurb");

with

tinyMCE.execCommand("mceAddEditor", false, "blurb");