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
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
Set Wordpress Featured Image Using Javascript
How To Fix PHP Random Being The Same
Why no WebP Support with Wordpress
Replace Wordpress Cron With Linux Cron
Customize Yoast Canonical URL Programmatically
[Centos] Delete All Files And Folders That Contain a String