Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

1 Answer 1

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

 
discard

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.