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/300); // 修改数字300调整时间
  $output .= '共计' . $text_num . '字,阅读大约' . $read_time  . '分钟。';
  return $output;
}

修改zib-single.php文件

在主题目录zibll/inc/functions/zib-single.php文件中,文章分页函数(大概是260行,因为我的代码有改动,所有不确定行数,见下图)下面添加下方代码即可。

添加这句代码:

<!--文章字数和阅读时间--><i class="fa fa-hourglass-start"></i> <?php echo count_words_read_time(); ?>
<div class="relative">
                <i class="line-form-line"></i>
                <?php if (!$is_show_cover) { ?>
                    <div class="article-meta abs-right muted-color radius">
                        <!--文章字数和阅读时间--><i class="fa fa-hourglass-start"></i> <?php echo count_words_read_time(); ?>
                        <?php echo $posts_meta; ?>
                    </div>
                <?php } ?>
</div>
© 版权声明
THE END
喜欢就支持一下吧
点赞131赞赏 分享
评论 抢沙发
头像
欢迎光临不念博客,留下您的想法和建议,祝您有愉快的一天~
提交
头像

昵称

取消
昵称代码图片

    暂无评论内容