代码实现前台文章界面显示文章字数统计代码
之前只能后台显示,现在前台也就可以显示啦
主题 全局配置文件 中
在functions.php
文件中加入以下代码:
有些主题会是在functions-theme.php
文件中:
//字数统计 www.ly522.com
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 ($text); ?>
放在文章配置文件(合适的位置就可以了)测试中文统计正常,英文统计字母
效果图(可以看标题下面哦)
![图片[1]-WordPress添加文章字数统计代码-乡野博文](http://www.zau.cn/wp-content/uploads/2022/02/20220214200131-2.png)
您阅读这篇文章共花了: 0小时00分00秒
THE END
暂无评论内容