Skip to content

Instantly share code, notes, and snippets.

@uditveerwani
Last active August 29, 2015 14:06
Show Gist options
  • Save uditveerwani/601d7cfd4166ea428a80 to your computer and use it in GitHub Desktop.
Save uditveerwani/601d7cfd4166ea428a80 to your computer and use it in GitHub Desktop.
Wordpress Excerpt Filter for Chinese Text
<?php
function ellipsis($text, $max=100, $append='&hellip;&hellip;'){
if (strlen($text) <= $max) return $text;
$text = strip_shortcodes($text);
$text = strip_tags($text);
$out = mb_substr($text,0,$max);
if (strpos($text,' ') === FALSE) return $out.$append;
return preg_replace('/\w+$/','',$out).$append;
}
add_filter('get_the_excerpt', 'chinese_excerpt_filter');
function chinese_excerpt_filter($excerpt){
if (function_exists('icl_get_languages')) {
if (ICL_LANGUAGE_CODE == 'zh_CN') {
$excerpt = ellipsis($excerpt, 150);
}
}
return $excerpt;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment