I’m proud to present my first Wordpress plugin, Words in Post. All it does is count up the number of the words in a post and spit them out. By sticking this code in the index.php template of Wordpress, I can create a title line that looks like this:
Geekery � 49 words � lee @ 2:50 am
This is better than using the following simple grab that I had heard about here.
<?php echo(str_word_count(get_the_content())); ?> words
The preceding doesn’t grab anything past the <!--more--> and counts tags incorrectly.
Thanks to Nick Momrik for the inspiration.
1-15-05 update: Version 1.1. Thanks to Alderete’s suggestion, the function returns a number instead of echoing. See the php for instructions.
Download Words in Post plugin version 1.1 here. Rename it from .phps to .php and run with it.

January 14th, 2005 at 3:25 am
I use a word count plugin from way back when. It also does a sum of the total words posted. Does yours also do a total of all posts?
I will try out your plugin to see if there is a difference between it and the one I’m using now. Thanks for putting this together and sharing it with the WP community!
January 14th, 2005 at 3:33 am
Mine doesn’t but get_post_word_count from Nick Momrik does. You can find it at http://mtdewvirus.com/wp-hacks/ and was the inspiration for this script.
January 15th, 2005 at 5:34 am
I might suggest that the plug-in return the number of words, rather than output it, so that you can pass the string along to other functions, for example, so it can be put in the “Read More” string, e.g.:
< ?php the_content('Read the rest of this entry (' . words_in_post() . ' words) »'); ?>January 15th, 2005 at 2:49 pm
A fine suggestion, Alderete. Done! Version 1.1 is created. See the post.
Hmm. To make it do correctly what you’re suggesting, we need a function that looks for the MORE bar and counts the text -after- it. Not hard… I’ll see what I can do. Or give it a shot yourself.
January 15th, 2005 at 3:21 pm
Oh, sorry, I wasn’t clear about what to count. In my usage snippet above, it’s just getting the article total word count, and that’s just fine for my purposes. I don’t actually want to count just the words after the < ! --more-->, but the count for the entire article.
January 15th, 2005 at 3:44 pm
Well good then! I’m still going to try and make a “words after more” plugin. :-)
January 27th, 2005 at 3:57 pm
Hi,
I tried out your plugin and noticed that it doesn’t count individual letters as words. For example:
“I love goats” would count as two words, as the word “I” is not counted. Any chance you can fix this?
January 27th, 2005 at 8:10 pm
Hmm. I’ll look into it. But no promises.
January 30th, 2005 at 5:16 pm
for whatever reason, i had to modify the plugin to pull from the proper db by adding
$tablepostsvariable as a global, and using it as the FROM instead of$wpdb->posts. i’m using WP 1.2.2.works great though, after that fix. thanks
April 19th, 2005 at 10:26 pm
Why not just use
str_word_count(strip_tags($post->post_content))
It works great and accurately as far as I can see. Additionally it doesn’t do an extra SQL query like your plugin to get the post content. The post_content is already available from $post.
August 21st, 2005 at 3:42 pm
What does this mean
How do i use this?
August 21st, 2005 at 4:55 pm
alos, I am getting this error like 6 times int he admin panel
Warning: Cannot modify header information - headers already sent by (output started at /home/mydomain/public_html/revivalblog/wp-content/plugins/word-count.php:26)
August 21st, 2005 at 7:13 pm
>Why not just use str_word_count(strip_tags($post->post_content))
reread my initial post.
>this error like 6 times
You might have inserted an extra space or carriage return (or are missing something) at the beginning of the script. It works peachy-keen for me.
October 5th, 2005 at 11:10 am
thank you SO much for the code to put the count words on my site. it’s greatly appreciated.
take care.