Get my FREE ebook:
"SEO FOR BLOGS: The Ultimate Guide"
Limited Time Offer!

How To Display The Word Count Of Your WordPress Blog Posts

If you are a numbers’ guy and would like to display the word count of all you blog posts, there is an easy way to do that. You just need to create a new function in the functions.php file of your own WordPress theme by pasting the following code:

1
2
3
4
5
6
7
8
9
10
11
function wordcount(){
    ob_start();
    the_content();
    $postcontent = ob_get_clean();
    return sizeof(explode(" ", $postcontent));
}

Then you need to call the function where you want to display the word count of your posts (for example in your single.php file), by pasting the following code within the loop:

1
<?php echo wordcount(); ?>
Commenting Contest
If you enjoyed this article, Get email updates
(It's Free)
Sté Kerwer
Post written by: Sté Kerwer
Bonjour from France. My name is Stéphane Kerwer and Dukeo.com is my blog. I do most of the heavy lifting in here but from time to time, you may see some guest posts. If you wish to receive updates about Dukeo, subscribe to RSS Feed, follow Dukeo on twitter or become a fan on Facebook.
11 Comments
  1. Michelle
    Michelle

    What if you’re a numbers gal? ;) haha just messing around with you, this is super helpful! For guys and gals alike!

    • Sarah
      Sarah

      LOL @ numbers gal haha me too!

  2. Shad
    Shad

    Again I am stealing this coolness for my WordPress. Thanks a ton, man!

  3. Samie
    Samie

    So this will display the word count to the readers publicly? Or just when I type it out? I definitely do think that could come in handy.. I love the feeling of getting lost while writing and being totally shocked by the word total. It makes me feel like I got a lot accomplished :)

    • John
      John

      It looks like we will just have to apply it and find out!

  4. Liz
    Liz

    This looks pretty cool! I wonder what it will look like.. I’m gonna try it!

  5. Jony
    Jony

    These are some neat tricks that you post on here, I think it comes very much in handy for anyone who has a wordpress site. Very cool of you to post these.

  6. Dana
    Dana

    I’m definitely applying this to my site. Word count is always a useful figure to measure yourself by.

  7. It seems to be very simple to do. Thank you so much for sharing it, I will definitely check it out

  8. Anon
    Anon

    I’m not sure why readers would care about the word count- are they going to be particularly impressed by it? Either way, this is a cool gadget, and it couldn’t hurt to apply it and see the readers’ reactions.

  9. AffMaster
    AffMaster

    It definitely couldn’t hurt to have another figure listed, something that could draw a reaction from readers, or something that you yourself can use to analyze your success rate i.e. do posts with higher word counts get more attention or something like that.

arrow