wordpress添加文章字数统计代码
1、将以下代码加到主题的 functions.php 文件最后一个 ?> 的前面。
//字数统计
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;
}
}
2、再把调用统计代码加到自己认为适合的位置,如 single.php 文件的某个位置。
<?php echo count_words ($text); ?>
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/400);
$output .= '本文共' . $text_num . '个字,预计阅读时间需要' . $read_time . '分钟。';
return $output;
}
2、再把调用统计代码添加到 single.php 文件适合的位置即可。
<?php echo count_words_read_time(); ?>
小半WordPress AI助手:开源免费的AI插件,为WordPress网站注入智能内容创作能力
WordPress ai助手:为 WordPress 用户提供集成多种 AI 模型的功能
上面是“wordpress添加文章字数统计和预计阅读时间代码”的全面内容,想了解更多关于 wordpress 内容,请继续关注web建站教程。
当前网址:https://ipkd.cn/webs_2077.html
workflows工作流
一只放屁虫甲虫ComfyUI工作流
一只沮丧的卡通小丑鱼ComfyUI工作流
荷塘月色ComfyUI工作流
一个红头发明亮眼睛的漂亮女人
在地铁站里一个迷茫的非主流姑娘
一只猫捧着一条鱼ComfyUI工作流
一杯咖啡蒸汽形成云ComfyUI工作流
一个纸杯蛋糕ComfyUI工作流
猜你喜欢
声明:本站提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请发送到邮箱:admin@ipkd.cn,我们会在看到邮件的第一时间内为您处理!

css3画弹珠,可以滚动!
纯css翻书效果
做一个好玩的时钟翻牌效果
js实现table表格动态新增行和列表
利用css3做一个动态loading效果
css3实现星球旋转
css3绘制一个会动的大嘴鸟










