WordPress tutorials: Display word count

Wpsnipp – Since WpRecipes has been launched, I had numerous requests to create a function that can display the word count of a post content. So, here is a function to do it easily.Adding this first PHP code snipp in your funtions.php then place the echo wcount(); within the loop of your wordpress theme and return the word count for the post.



function wcount(){
$content = ob_get_clean();
return sizeof(explode(" ", $content));

Once done, you can call the function within the loop to get the number of words of the current post:

echo wcount();

Leave a comment