您的位置:首页 > 教程笔记 > 综合教程

WordPress添加文章字数统计和阅读时间

2023-11-16 11:00:26 综合教程 142

wordpress站点上在自己网站文章的底部添加文章字数统计和阅读时间的功能。

这个功能可以统计一篇文章总共有多少字,并且预计文章阅读时间。

1.打开自己的WordPress模板文件functions.,放上相关的函数代码。

//字数和预计阅读时间统计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;}

2.在网站的文章模板single.里使用以下的标签来调用相关数据。

<? echo count_words_read_time(); ?>

3.这样Wordpress程序会自动统计文章字数和阅读时间了。

相关推荐