WordPress升级4.3后,不能正确统计中文摘要字数的解决方法

  WordPress升级4.3之后,首页摘要字数统计不正确,只统计了英文而不统计中文,导致中文摘要几乎要包含到全篇的内容。

  解决方法为,打开/wp-includes/formatting.php,找到function wp_trim_words( $text, $num_words = 55, $more = null ) 中的:

/*
* translators: If your word count is based on single characters (e.g. East Asian characters),
* enter 'characters_excluding_spaces' or 'characters_including_spaces'. Otherwise, enter 'words'.
* Do not translate into your own language.
*/
if ( strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' ) === 0 && preg_match( '/^utf\-?8$/i', get_option( 'blog_charset' ) ) ) {
$text = trim( preg_replace( "/[\n\r\t ]+/", ' ', $text ), ' ' );
preg_match_all( '/./u', $text, $words_array );
$words_array = array_slice( $words_array[0], 0, $num_words + 1 );
$sep = '';
} else {
$words_array = preg_split( "/[\n\r\t ]+/", $text, $num_words + 1, PREG_SPLIT_NO_EMPTY );
$sep = ' ';
}

参考注释,根据需要把这一行
strpos( _x( 'words', 'Word count type. Do not translate!' ), 'characters' )

中的‘words’ 修改为‘characters_excluding_spaces’ 或‘characters_including_spaces’ 即可。