tinymce.activeEditor.getContent() returns empty string

0
76
Asked By Isaac Ortega On

I am trying to write some javascript code that will pull the content from the WordPress editor. I found code online that does this but it doesn't seem to be working for me. If i use the following code, I see an empty string message in the console.

var content = tinymce.activeEditor.getContent();
console.log(content);

Why isn't the content being returned from this? If i check the objects, I can see activeEditor is set to something so I don't know why it would be giving back an empty string. I have made sure that the editor is in visual mode.

1 Answer

Answered By Simon Furrel On

This can sometimes happen when there is more than one tinyMce editor on the screen. It causes the activeEditor part of the variable to get messed up a bit. There are a couple of WordPress plugins that will make use of another text area, even if its a hidden one that isn't visible on the screen. Try changing your code to directly target the main content editor.

The following code should allow you to see the output of your content. If not, make 100% sure the visual tab is selected and not the text tab.

 

var content = tinymce.editors.content.getContent();
console.log(content);

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.