WordPress预估阅读文章时间

ė 1,215 6 1
本文最近更新于23.01.30 周一请自行判断新内容

之前在WordPress中加入function.php文章估计阅读时间代码是用的bigfa的,发现并不准确,2727字估算约19分钟,实际阅读完5分钟左右。网上又找到一段代码,才符合实际。略有修改

// 字数统计
function count_words ($text) {
global $post;
if ( '' == $text ) {
$text = $post->post_content;
if (mb_strlen($output, 'UTF-8') < mb_strlen($text, 'UTF-8')) $output .= mb_strlen(preg_replace('/\s/','',html_entity_decode(strip_tags($post->post_content))),'UTF-8') . '字';
return $output;
}
}

引用代码<?php echo count_words(); ?>

//阅读时间,正常每分钟500字
function read_time( $return = false) {
$wordcount = round(count_words(), -2);
$minutes = ceil($wordcount / 500);

if ($wordcount <= 500) {
$output = '阅读时间约1分钟';
} else {
$output = '阅读时间约'.$minutes.'分钟';
}
echo $output;
}

引用代码<?php echo read_time(); ?>

  • 灵魂发问:谁告诉你我国防空洞位置了吗?怕是99%中国人不知道,我也不知道,为什么,因为没告诉咱们啊!怕是很多当官的都不晓得吧!所以别老想着打这个那个,真打起来,你躲都不知道躲哪?最好的位置是到没有军事区,机场等落后位置,因为人家炸这些位置不仅没有利益还会被国际谴责。 --- 2025/03/08
主机推荐
留言区 (1,215阅已有1条留言,俺要占位
:网友留言区仅供网友表达其个人观点,并不表明栖息邦最终立场。



  1. 1F

    很有趣的功能~

    2020年11月10日 17:35 回复
管理员登录
注册

提示:点击上下面区域关闭

字号调整

View My Stats
空位 空位
本次加载耗时:1.652s