A better default except, Remove multiple white spaces from the except as well as splitting safely on UTF8 strings. Props Denis-de-Bernardy for the UTF8 split. Fixes #10376
git-svn-id: https://develop.svn.wordpress.org/trunk@13942 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
db6a40aa27
commit
c57a54f082
|
@ -1844,11 +1844,13 @@ function wp_trim_excerpt($text) {
|
||||||
$text = strip_tags($text);
|
$text = strip_tags($text);
|
||||||
$excerpt_length = apply_filters('excerpt_length', 55);
|
$excerpt_length = apply_filters('excerpt_length', 55);
|
||||||
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
|
$excerpt_more = apply_filters('excerpt_more', ' ' . '[...]');
|
||||||
$words = explode(' ', $text, $excerpt_length + 1);
|
$words = preg_split("/[\n\r\t ]+/", $text, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY);
|
||||||
if (count($words) > $excerpt_length) {
|
if ( count($words) > $excerpt_length ) {
|
||||||
array_pop($words);
|
array_pop($words);
|
||||||
$text = implode(' ', $words);
|
$text = implode(' ', $words);
|
||||||
$text = $text . $excerpt_more;
|
$text = $text . $excerpt_more;
|
||||||
|
} else {
|
||||||
|
$text = implode(' ', $words);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
|
return apply_filters('wp_trim_excerpt', $text, $raw_excerpt);
|
||||||
|
|
Loading…
Reference in New Issue