WordPress文章页面添加文章字数和阅读时间

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;
}

第二步

在主题目录zibll/inc/functions/zib-single.php,把下面代码添加到260行处(如下图)

(温馨提示:由主题不断更新放的位置也有可能不同,目前显示主题版本:V5.6,如网站更新自行查找放置)

<!--文章字数和阅读时间--><i class="fa fa-hourglass-start"></i> <?php echo count_words_read_time(); ?>
图片[1]-WordPress文章页面添加文章字数和阅读时间-乡野博文

第三步

温馨提示需要给子比后台设置的:图片封面关闭要不然不会显示(如图)

图片[2]-WordPress文章页面添加文章字数和阅读时间-乡野博文
温馨提示:本文最后更新于2022-05-12 03:28:34,某些文章具有时效性,若有错误或已失效,请在下方留言或联系乡野博文
您阅读这篇文章共花了: 0小时00分00秒
-----本页内容已结束,喜欢请分享!-----
© 版权声明
THE END
喜欢本站内容,请点【点赞】【分享】和【收藏】~
点赞11 分享
评论 抢沙发

请登录后发表评论

    暂无评论内容