Skip to content

Instantly share code, notes, and snippets.

@CoeusCC
Created May 17, 2016 19:07
Show Gist options
  • Save CoeusCC/7203e190d908aa5eca15334d40ea6b62 to your computer and use it in GitHub Desktop.
Save CoeusCC/7203e190d908aa5eca15334d40ea6b62 to your computer and use it in GitHub Desktop.
Target TinyMCE instance in WordPress post editor and return an estimated word count
function countWordsInWpEditor() {
var html;
var text;
var words;
var focusedTextField = document.getElementById("tinymce");
html = focusedTextField.innerHTML;
text = html.replace(/(<([^>]+)>)/ig,"")
words = text.split(" ");
return words.length;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment