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


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

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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