tinymce editor getContent null in WordPress

I am trying to use the getContent feature of the Tinymce editor in WordPress admin area but to no avail.

Here is a working pen of what I want to do

https://codepen.io/anon/pen/oWxjyM?editors=1111

HTML

<textarea class="wp-editor-area" rows="20" autocomplete="off" cols="40" name="wprss_ftp_post_prepend" id="wprsspostprepend">&lt;p&gt;To give is good&lt;/p&gt;</textarea>

JS

jQuery(document).ready(function() {
  $("#wprsspostprepend").addClass("prepend_editor");
var name = "wprsspostprepend";
if($("#" + name).length > 0) {

  tinyMCE.init({
        mode : "specific_textareas",
        editor_selector : "prepend_editor"  
});
   var content =  tinyMCE.activeEditor.getContent();
  alert(content);
    tinyMCE.activeEditor.setContent("<div id='random-wrap'>" + content + "</div>");
}
 });

Why am I getting the null reference error in WordPress if it works in codepen.

Read more here: tinymce editor getContent null in WordPress

Leave a Reply

Your email address will not be published. Required fields are marked *