👋🏼Welcome to my WP-Host blog where I am excited to share my knowledge and expertise on WordPress hosting and website construction tutorials with you. Let’s connect and learn from each other! You can reach me at info@yrshare.com.
How WordPress articles show word count and reading time: In this article, we will share a simple WordPress tutorial that demonstrates how to display the word count and reading time of your WordPress articles, resulting in an improved user reading experience on your website. We hope this will be helpful for you.
Continue to share the wordpress website building tutorial, and today I will share with you a method to realize the display of word count and estimated reading time in articles.
You may have seen that some websites have this function. How is this achieved?
Next【WP-Host/悦然wordpress建站】will share with you two implementation methods.
Method 1: use code
Add the following code to the functions.php file of your current wordpress builder theme.
//How WordPress articles show word count and reading time
function 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/400);
$output .= '本文共有' . $text_num . '个字,阅读需要' . $read_time . '分钟。';
return $output;
}
The above Chinese tips can be modified by yourself, or changed to English.
The above code can also be added to the Code Snippets plugin. If you add too many pieces of code to the functions.php file of your website, it will be more convenient to use this plugin.
Next, we also need to add the following code to the single.php file of the current theme to take effect:
<?php echo count_words_read_time(); ?>
Method 2: Use a plugin
Using plug-ins is the easiest way. Yueran found two plug-ins, namely Reading Time and Reading Time WP. It is recommended to use Reading Time WP here, which can be downloaded from the wordpress plug-in center, or downloaded and installed through the following address.
After enabling it, you can set it up. As shown in the picture above, the setting items are very simple. Although it is in English, it does not affect the use.
Summary
The above is the wordpress website building tutorial shared with you today. Adding word count and estimated reading time to the website can improve some website user experience.
This is more suitable for some websites with rich content. If the content of your website is basically within 1000 words, it is not recommended to add it, which is meaningless.