Display the total number of words in a post.
Steps
- Add the code below to
functions.php. - Save the file.
- 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));
}