想要给自己搭建的WordPress网站添加文章字数统计和阅读时间的方法

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

想要给自己搭建的WordPress网站添加文章字数统计和阅读时间的方法 (https://www.wp-admin.cn/) WordPress使用教程 第1张

  这个功能可以统计一篇文章总共有多少字,并且预计文章阅读时间。下面来学习一下方法:

  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里使用以下的标签来调用相关数据。

<?php echo count_words_read_time(); ?>

  3.这样Wordpress程序会自动统计文章字数和阅读时间了。

相关推荐

发表回复

房先生
我们将24小时内回复。
2024-05-11 06:26:56
您好,有任何疑问请与我们联系!
您的工单我们已经收到,我们将会尽快跟您联系!
[QQ客服]
2781198
加我微信
[电话联系]
13585372227
[电子邮件]
chaoneo@163.com
取消

选择聊天工具: