April 7, 2009
How to Get the Word Count in a Post
Thanks to WPRecipes, I have found an amazingly helpful tutorial how to get the word count in a post to show up on your index, or on your single page if you prefer. Here’s how we go about doing this.
Okay, first, open up your functions.php file in your themes directory, and paste the following code anywhere within:
function count_words($str){
$words = 0;
$str = eregi_replace(" +", " ", $str);
$array = explode(" ", $str);
for($i=0;$i < count($array);$i++)
{
if (eregi("[0-9A-Za-zÀ-ÖØ-öø-ÿ]", $array[$i]))
$words++;
} return $words;
}
Then, open up whereever you want the word count for your post to show up, be it the index.php or single.php, and paste this code anywhere within it:
Word count: post_content); ?>
And voila! The word count for your posts will be displayed!
Related posts:
- Display your tags in a dropdown menu
- Display the Author Who Edited a Post Last
- How to preset text in the WordPress post editor
- WordCamps for July 2009 – Montreal and UK
Previous Post and Next Post














TechZoomIn
July 3, 2009 at 1:57 am
Good one just searching to the count..Thanks for the info….