我感觉太累赘,字太多了,需要修改下,只显示全部字符统计即可
function character_count_shortcode( $atts ) {
$post_id = get_the_ID();
$post_content = get_post_field( 'post_content', $post_id );
$english_count = preg_match_all( '/\p{L}+/u', $post_content, $matches );
$chinese_count = preg_match_all( '/[\x{4e00}-\x{9fa5}]/u', $post_content, $matches );
$total_count = $english_count + $chinese_count;
return '<p> 本文字数 '.$total_count.'</p>';
}
add_shortcode( 'character-count', 'character_count_shortcode' );
删掉
,其中 '.$chinese_count.' 个中文字符,'.$english_count.' 个英文字符。