WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

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

I have two wp_editor() instances on pages and posts used to populate the sidebars of my three-column website. I would like to use the default wordpress word-count script on the two wp-editor areas to get the word-count of the content within them.

I enqueued the script and added the required HTML but the wordcount was always that of the main content editor area.

Has anyone managed to use this functionality with custom wp_editor areas and what HTML will I use?

I have searched on the web but could not find any examples where the default script is used.

Thanks in advance nav

share|improve this question
up vote 1 down vote accepted

Git this to work by using the following line of code in my theme's functions.php.

$wordcount = str_word_count( strip_tags( $content ), 0 );

I got this piece of code from a stackoverflow post.

The only disadvantage with this code is that it does not update dynamically which is not a big issue as the current wordcount will show up every time the post is updated.

The problem with using javascript on which event I should trigger the wordpress function on.

WordPress's wordcount functionality is tightly coupled with the default editor and I had to duplicate their javascript to try and get similar functionality which is not a good choice.

I would still like to get some thoughts on this by a more experienced WP developer.

Thank you. nav

share|improve this answer

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.