WordPress升級4.3之後,首頁摘要以及搜索結果摘要字數統計不正確,只統計了英文而不統計中文,導致中文摘要幾乎要包含到全篇的內容。
解決方法為,打開/wp-includes/formatting.php,找到如下內容:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
/* * 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’。
======
轉載自nex3z’s blog
One thought on “WordPress升級4.3後無法統計中文摘要字數的解決方法”