Skip to main content
Login Join
Snippet · PHP

Show Word Count for Posts

Shared by Amit Dholiya · July 4, 2026

11 views
Back to Snippets

Display the total number of words in a post.

Steps

  1. Add the code below to functions.php.
  2. Save the file.
  3. Call the function inside your theme.

Done — readers can see the article word count.

function get_post_word_count() {
    $content = get_post_field('post_content', get_the_ID());
    return str_word_count(strip_tags($content));
}
Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments