首页 Wordpress WordPress 文章字数统计代码

WordPress 文章字数统计代码

将下面代码扔到主题的 functions.php 文件
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;
}
}
调用代码
php
<?php echo count_words ($text); ?>

相关推荐

发表回复

邮箱地址不会被公开。