robert chan
robert chan

Reputation: 9

Add wysiwyg editor in WordPress textarea Meta Box

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

Upvotes: 0

Views: 4442

Answers (3)

snnsnn
snnsnn

Reputation: 13620

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'
        });
    }
});

Upvotes: 3

ludiccc
ludiccc

Reputation: 353

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

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

with

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

Upvotes: 0

Parth  Mahida
Parth Mahida

Reputation: 604

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>

Upvotes: 0

Related Questions