hosting tutorials WeChat Top

👋🏼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.

Email Me

(如果你会中文,可以点击微信图标与我联系。)

扫一扫加我

注:因个人英文水平有限,所以暂时只能为懂中文的朋友提供wordpress建站服务

微信:18200592859 或 yrwordpress

How WordPress articles show word count and reading time(Two methods)

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.

【WP-Host/悦然wordpress建站】
2023031803202799

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.

Download

https://downloads.wordpress.org/plugin/reading-time-wp.2.0.10.zip

2023031803204085

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.

2023031803202799

继续分享wordpress建站教程,今天给大家分享一个实现文章显示字数统计和预计阅读时间的方法。可能大家也看到过有些网站有此功能有,这是怎么实现的呢?

接下来【WP-Host/悦然wordpress建站】就给大家分享两个实现方法。

方法一:使用代码

把下面的代码添加到当前wordpress建站主题的functions.php文件中。

//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;
}

上面的中文提示可以自行修改,也可以改成英文的。

上面的代码也可以添加到Code Snippets插件中,如果你的网站functions.php文件添加过多段代码,那么使用这个插件会比较方便。

接下来我们还需要在当前主题的single.php文件中添加下面的代码才能生效:

<?php echo count_words_read_time(); ?>

方法二:使用插件

使用插件是最简单的方法,悦然建站找到了两个插件,分别是Reading Time、Reading Time WP,这里推荐使用Reading Time WP,可以在wordpress插件中心下载,也可以通过下面的地址下载安装。

下载地址

https://downloads.wordpress.org/plugin/reading-time-wp.2.0.10.zip

2023031803204085

启用之后设置一下就可以了,如上图,设置项很简单,虽然是英文,但并不影响使用。

总结

以上就是今天给大家分享的wordpress建站教程,给网站添加字数统计与估计阅读时间,可以提升一些网站用户体验。这比较适合一些文章内容丰富的网站,如果你的网站内容基本都是1000字以内的,那就不建议添加了,没什么意义。

WordPress Hosting / 悦然wordpress建站

WordPress Hosting / 悦然wordpress建站

【WordPress Hosting / 悦然wordpress建站】I am a WordPress hobby from China, and I like to communicate with friends from all over the world to learn WordPress website building and maintenance related knowledge.