![图片[1]-WordPress添加文章字数统计代码](https://www.ly522.com/wp-content/uploads/2018/08/1790-600x600.png)
代码实现前台文章界面显示文章字数统计代码 之前只能后台显示,现在前台也就可以显示啦
主题 全局配置文件 中
在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); ?>
放在文章配置文件(合适的位置就可以了)测试中文统计正常,英文统计字母
效果图(可以看标题下面哦)
![图片[2]-WordPress添加文章字数统计代码](https://www.ly522.com/wp-content/uploads/2018/08/1790-1-800x506.png)
© 版权声明
THE END















![表情[qiang]-轻刻年轮](https://www.ly522.com/wp-content/themes/zibll/img/smilies/qiang.gif)
666
- 最新
- 最热
只看作者