DISCLAIMER: this post is older than one year and may not be up to date with latest WordPress version.

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.

Simply open your functions.php file and paste this function in it:

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:

<?php echo wcount(); ?>

This recipe was inspired from this excellent tip.


  1. Thank you for this function!
    It can be used outside of WordPress as well though.

  2. Might be just myself but this is only an approximate and not an exact value. There are small differences between the true post count, however it is close enough.


  3. Sir thanks for sharing this but i have problem.. this is showing about just words without spacing.. i Need complete words including letters, spacing every thing……

Leave a Comment

Your email address will not be published. Required fields are marked *