Last active
August 29, 2015 14:06
-
-
Save uditveerwani/601d7cfd4166ea428a80 to your computer and use it in GitHub Desktop.
Wordpress Excerpt Filter for Chinese Text
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function ellipsis($text, $max=100, $append='……'){ | |
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