WordPress 文章字数统计代码
将下面代码扔到主题的 functions.php 文件
1 2 3 4 5 6 7 8 9 | //字数统计 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); ?> |