WordPress添加文章字数统计代码

图片[1]-WordPress添加文章字数统计代码
代码实现前台文章界面显示文章字数统计代码 之前只能后台显示,现在前台也就可以显示啦

主题 全局配置文件 中
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添加文章字数统计代码

购买后下载不了源码或源码功能失效请联系小编,确认后可立即退款,请勿无理投诉
© 版权声明
THE END
喜欢就支持一下吧
点赞3赞赏 分享
评论 共1条

请登录后发表评论

    暂无评论内容