CKEditor word count

There are a couple of ways you may want to do this – I’ve described two below. The first is a word count that runs itself and updates a value somewhere on the page, the second a word count initiated by the user.

Method 1: Using a timed function

My solution for the first method is simply a function that runs at a regular interval. It grabs the text from the specific CKEditor instance, performs a word count and updates a div on the page

Stick this function in the head of your document:

Put an element on the page and give it the id ‘wordcount’. Then after your CKEditor element is on the page, put another script tag in and run this:

That should do the job! It will update the word count every 5 seconds

Method 2: Using a CKEditor plugin

To do it this way we’ll need to create a folder in the CKEditor plugins directory. Name it wordcount and create a blank plugin.js file in there. Copy the code below in:

You might want to put a nice word count image icon in (icon.png). Here is a lame one I did – just save it into your word count plugin directory: word count icon

When you are initiating your CKEditor you’ll need to add the plugin in, something like this:

You should now have a button in your editor that will give you your word count. Hooray!

11 thoughts on “CKEditor word count

  1. Hi everyone, I implemented this solution and worked very well, except for one thing:

    I have two ckeditors in my page, and every time I insert any text in editor 1, the charcount of editor 2 is updated with charcount of editor 1.

    Has one ever experienced this?


  2. Hi,

    I am Usha Iyer, an Acquisition Editor with Packt Publishing. As an Acquisition Editor, it is my role to evaluate, develop and ultimately bring book ideas to publication. I am also responsible for finding the right author for any book; bringing them onboard, then working with them as the book is written.

    I have begun to develop a microcontent ( microcontent title meaning just 60 pages long ) title on ‘CKEditor’, and am now looking for an author to write this book.

    Please contact me if you are interested in writing this book and I would love to discuss the opportunity with you further.

    Even if you do not want to involve yourself in the project, can you please suggest someone who may suit this project?




Leave a Reply

Your email address will not be published.