Important changes to Tiny Cloud pricing > Find out more

NOTE: TinyMCE 5 reached End of Support in April 2023. No more bug fixes, security updates, or new features will be introduced to TinyMCE 5. We recommend you upgrade to TinyMCE 6 or consider TinyMCE 5 Long Term Support (LTS) if you need more time.

Word Count plugin

Show a word count in the TinyMCE status bar.

Contribute to this page

The Word Count plugin adds the functionality for counting words to the TinyMCE editor by placing a counter on the right edge of the status bar. Clicking Word Count in the status bar switches between counting words and characters. A dialog box with both word and character counts can be opened using the menu item situated in the Tools drop-down, or the toolbar button.

Basic setup

tinymce.init({
  selector: 'textarea',  // change this value according to your HTML
  plugins: 'wordcount',
  toolbar: 'wordcount'
});

Toolbar buttons

The Word Count plugin provides the following toolbar buttons:

Toolbar button identifier Description
wordcount Opens a word count dialog showing word and character counts.

These toolbar buttons can be added to the editor using:

Menu items

The Word Count plugin provides the following menu items:

Menu item identifier Default Menu Location Description
wordcount Tools Opens a word count dialog showing word and character counts.

These menu items can be added to the editor using:

Commands

The Word Count plugin provides the following JavaScript command.

Command Description
mceWordCount Opens the Word Count summary dialog.

Example

tinymce.activeEditor.execCommand('mceWordCount');

API

The Word Count plugin exposes an API for retrieving the word and character count of either the whole document or the current editor selection. Following is an example of how to retrieve each property.

Example: Using the wordcount plugin APIs

var wordcount = tinymce.activeEditor.plugins.wordcount;

console.log(wordcount.body.getWordCount());
console.log(wordcount.body.getCharacterCount());
console.log(wordcount.body.getCharacterCountWithoutSpaces());

console.log(wordcount.selection.getWordCount());
console.log(wordcount.selection.getCharacterCount());
console.log(wordcount.selection.getCharacterCountWithoutSpaces());

Can't find what you're looking for? Let us know.

Except as otherwise noted, the content of this page is licensed under the Creative Commons BY-NC-SA 3.0 License, and code samples are licensed under the Apache 2.0 License.