How To Fix Chinese Language WordPress Excerpts Issue

chinese-wp-excerpt-fixWordPress excerpt works fine in most languages character, however if its on Chinese pin yin language, the excerpt will not work. The excerpt count cannot filter the character because of ‘no spacing’ in Chinese character. You can use the following fix for Chinese language:

Add this code into your functions.php

[php]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 = mb_substr( $output, 0, 50 ) . ‘…’;
return $output;
add_filter( ‘get_the_excerpt’, ‘dez_filter_chinese_excerpt’ );[/php]

You can edit the ’50’ to any number you preferred.

Scroll to Top