» » You are reading »

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

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' );

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

http://cdn.dezzain.com/1/2016/08/chinese-wp-excerpt-fix-768x509.jpghttp://cdn.dezzain.com/1/2016/08/chinese-wp-excerpt-fix-150x150.jpgRichie KS Snippetsphp,Wordpress
WordPress 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 You...

Leave a Reply

Your email address will not be published. Required fields are marked *