How to display the word count of WordPress post
Filed under Labs
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(); ?> |
Posts you may like:
Delete records within a specific Range from MySQL table
If you want to delete a range of records from MySQL table then you can …
php pagination code example using MySql database
Here is a working code for pagination using PHP and MySql database. Its is tested …
How to include php headers on html site
PHP is a powerful language for web development, it have many in built functions. Here …
Meta refresh tag HTTP-EQUIV “REFRESH”
The refreshing time of a webpage can be define by using html tag HTTP-EQUIV “REFRESH”. …
Open link in a new window
Here is some ways to make html links for a webpage, it will be useful …