文章字数统计和预计阅读时间

图片[1]-文章字数统计和预计阅读时间-墨初小屋

打开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()函数是文章前面的点赞信息等等,调用代码可以加到里面最后

代码转载自

https://boke112.com/3845.html

© 版权声明
THE END
喜欢就支持一下吧
点赞0
分享
评论 抢沙发
墨初的头像-墨初小屋

昵称

取消
昵称表情代码图片