WordPress主题在文章页添加文字数量跟阅读时间

1、在主题目录下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/1800); // 修改数字1800调整时间
  $output .= '共计' . $text_num . '字,阅读大约' . $read_time  . '分钟';
  return $output;
}

2、在主题目录zibll/inc/functions/zib-single.php,把下面代码添加到<div class=”article-meta abs-right muted-color radius”></div>之间。

<!--文章字数和阅读时间--><i class="fa fa-hourglass-start"></i> <?php echo count_words_read_time(); ?>

说明:文章字数和阅读时间都不是很准,同时用处也不是很大…喜欢的话自己拿去试试吧!

👋 感谢您的观看!

© 版权声明
THE END
喜欢就支持一下吧
点赞0 分享