![图片[1]-文章字数统计和预计阅读时间-墨初小屋](http://mochu.co/wp-content/uploads/2022/02/wordpress.jpg)
打开functions.php文件,在末尾添加如下函数
第五行的400是阅读速度,一般人的阅读速度为300-500字每分钟,可自行修改
// 字数和预计阅读时间统计
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;
}
接下来则要在需要显示统计信息的地方调用上面的函数
打开 inc/functions/zib-single.php 文章页主内容文件,添加如下调用代码到合适的地方
<?php echo count_words_read_time(); ?>
提示:zib_single_box_header()函数是文章前面的点赞信息等等,调用代码可以加到里面最后
代码转载自
© 版权声明
文章版权归作者所有,转载请注明来源。
THE END
喜欢就支持一下吧