WordPress博客网站无插件实现WordPress文章字数统计功能,首先在founctions.php文件插入以下代码:

1
2
3
4
5
6
7
8
9
/*WordPress文章字数统计功能:http://guminfeng.cn*/
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;
}
}

然后,在文章页面需要添加显示文章字数的地方插入代码:

1
<?php echo count_words ($text); ?>