学习WordPress是很多建站新手都要面对的,今天小编为大家介绍一个WordPress小功能,就是在自己网站文章的底部添加文章字数统计和阅读时间的功能。想要给自己搭建的WordPress网站添加文章字数统计和阅读时间的方法是什么?

这个功能可以统计一篇文章总共有多少字,并且预计文章阅读时间。下面来学习一下方法:
1.打开自己的WordPress模板文件functions.php,放上相关的函数代码。
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;
}
2.在网站的文章模板single.php里使用以下的标签来调用相关数据。
3.这样Wordpress程序会自动统计文章字数和阅读时间了。
立冬,
初雪,
送给大家一个[心]…
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me?
Thank you for your sharing. I am worried that I lack creative ideas. It is your article that makes me full of hope. Thank you. But, I have a question, can you help me? https://accounts.binance.com/id/register-person?ref=V2H9AFPY