WordPress article page to increase the number of words reading time statistical effect

Do we see some friends’ WordPress article pages with statistics of the number of words in the current article and the estimated reading time. Although this function does not have much use, it can still improve some functional experience. How to add this function? Here, we also sorted out this method and added it when necessary.

First, statistics article word number

/ / word count by wpfans.orgfunction cnwper_ count_ words ($text) {global $post;if ( ” == $text ) {$text = $post->post_ content;if (mb_ strlen($output, ‘UTF-8’) < mb_ Strlen ($text, ‘UTF-8’)) $output. = ‘of’. MB_ strlen(preg_ replace(‘/s/’,”,html_ entity_ decode(strip_ tags($post->post_ Content)),’utf-8 ‘).’ words ‘;return $output;}}

Add to our current topic Functions.php Page, and then when you need to call directly with the following code call.

<?php echo cnwper_ count_ words($text); ?>

Second, estimate the reading time

/ / calculate the estimated reading time by wpfans.orgfunction count_ words_ read_ time () {global $post;$text_ num = mb_ strlen(preg_ replace(‘/s/’,”,html_ entity_ decode(strip_ tags($post->post_ content))),’UTF-8′);$read_ time = ceil($text_ Num / 300); / / modify the number 300 to adjust the time$output. =’total text ‘. $text_ Num. ‘words, estimated reading time’ $read_ Time. ‘minutes. ‘;return $output;}

Then call as needed.

<?php echo count_ words_ read_ time(); ?>

If you need a specific style, you can set it by yourself.

Related Article
WordPress displays the registration time of the login user in the frontend

When using WordPress to build a website, some users want to display the user registration time in the frontend, but Read more

WordPress adds the number of SQL queries at the bottom

An excellent woodpress theme is definitely that the less SQL consulting is used, the better. How can we see how Read more

Some WordPress articles can be seen after comments / replies

If we want to hide part of the content of the article and need the user's comments and replies to Read more

WordPress common template function reference document

Basic template filefile namedescribe style.css Theme style file index.php Home page template file header.php Header template file single.php Single article Read more

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture.
Anti-spam image