Some users reported that the WordPress excerpts word count is incorrect in languages such as Chinese and Japanese. The PHP snippets should help:
Chinese
function dez_filter_chinese_excerpt( $output ) {
global $post;
//check if its chinese character input
$chinese_output = preg_match_all("/\p{Han}+/u", $post->post_content, $matches);
if($chinese_output) {
$output = sprintf( '%1$s <p class="read-more-button-container"><a class="button" href="%2$s">%3$s</a></p>',
mb_substr( $output, 0, 50 ) . '...',
get_permalink(),
__( 'Read more', 'generatepress' )
);
}
return $output;
}
add_filter( 'get_the_excerpt', 'dez_filter_chinese_excerpt' );
Japanese
add_filter('get_the_excerpt', function($excerpt) {
$is_japanese = preg_match('/[\x{4E00}-\x{9FBF}\x{3040}-\x{309F}\x{30A0}-\x{30FF}]/u', $excerpt);
$excerpt_length = 55;
if ( $is_japanese && mb_strwidth($excerpt) > $excerpt_length ) {
return sprintf( '%1$s %2$s',
mb_strimwidth($excerpt, 0, $excerpt_length, ' ', 'UTF-8'),
generate_excerpt_more('')
);
}
return $excerpt;
});