I want to insert a shortcode in the WordPress Post Editor from javascript (not a tinymce plugin). I currently use:
tinyMCE.activeEditor.execCommand('mceInsertContent', false, "[SHORTCODE]test[/SHORTCODE] ");
but this only seems to work when the editor is in “Visual” mode (and sometimes activeEditor == null). How do I accomplish this regardless of the state of the editor? (I’d think this is a fairly common scenario)
I was pulling my hair out on this one, but I might have figured it out.
Try this (with jQuery):
Basically, you need to set the value of the textarea directly if the editor is hidden.