WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

So I understand that the visual editor uses something called TinyMCE. How do I retrieve the html that the user selects from the visual editor? I am basically trying to create a button that gets the selected html and replaces it.

share|improve this question
up vote 1 down vote accepted

The visual editor (TinyMCE) has its own API and since its a JavaScript Based editor you can get the selection using JavaScript very easily

share|improve this answer
Thanks Bainternet! – Shaan Sep 26 '11 at 21:38
And just for ppl to note, you can replace the selected content using tinyMCE.activeEditor.selection.setContent('<div>sample content</div>'); – Shaan Sep 27 '11 at 2:26
So, you could use this as a replacement to send_to_editor, could you not? – Manny Fleurmond Mar 20 '13 at 14:42

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.