How to display the word count of WordPress post

If you would like to display the word count of a post content, then here is an easy method. Simply add below function to your functions.php file in theme folder and call the function within the loop to display number of words of the current post.

 
<?php
 
function wordcount(){
    ob_start();
    the_content();
    $postcontent = ob_get_clean();
    return sizeof(explode(" ", $postcontent));
}
 
 
?>

Call the above function by pasting the following code in your template within the loop.

 
	<?php echo wordcount(); ?>

Related posts:

HTML5 page structure

HTML5 offers more powerful structure comparing to older versions of Html. There are many new …


Partner with Us

We are providing an exclusive partnership offer to individuals and companies who are interested in setting up their own web design & development company. For more information about how to partner with us, please contact us