Created
July 22, 2013 05:50
-
-
Save WenLiangTseng/6051554 to your computer and use it in GitHub Desktop.
Wordpress-中文摘要寫法
This file contains hidden or 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 | |
//Normal Version | |
function chinese_excerpt($text, $lenth=100) { | |
$text = mb_substr($text,0, $lenth); | |
return $text; | |
} | |
add_filter('the_excerpt', 'chinese_excerpt'); | |
//Improved Version | |
//加上UTF-8參數以及strip_tags, | |
//移除html標記,避免影響版面 | |
function chinese_excerpt($text, $lenth=36) { | |
$text = mb_substr(strip_tags($text),0, $lenth, 'UTF-8').'…'; | |
return $text; | |
} | |
add_filter('the_excerpt', 'chinese_excerpt'); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment