Give plugins and themes simple control over the text displayed at the end of an autogenerated excerpt. Fixes #10395 props ramiy.

git-svn-id: http://svn.automattic.com/wordpress/trunk@11907 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
westi 2009-09-09 16:34:44 +00:00
parent 3dfaac6960
commit b4e7804bf0
1 changed files with 6 additions and 2 deletions

View File

@ -1696,9 +1696,12 @@ function human_time_diff( $from, $to = '' ) {
* that, then the string '[...]' will be appended to the excerpt. If the string * that, then the string '[...]' will be appended to the excerpt. If the string
* is less than 55 words, then the content will be returned as is. * is less than 55 words, then the content will be returned as is.
* *
* The 55 word limit can be modified by plugins/themes using the excerpt_length filter
* The '[..]' string can be modified by plugins/themes using the excerpt_more filter
*
* @since 1.5.0 * @since 1.5.0
* *
* @param string $text The exerpt. If set to empty an excerpt is generated. * @param string $text The excerpt. If set to empty an excerpt is generated.
* @return string The excerpt. * @return string The excerpt.
*/ */
function wp_trim_excerpt($text) { function wp_trim_excerpt($text) {
@ -1712,10 +1715,11 @@ function wp_trim_excerpt($text) {
$text = str_replace(']]>', ']]>', $text); $text = str_replace(']]>', ']]>', $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', '[...]');
$words = explode(' ', $text, $excerpt_length + 1); $words = explode(' ', $text, $excerpt_length + 1);
if (count($words) > $excerpt_length) { if (count($words) > $excerpt_length) {
array_pop($words); array_pop($words);
array_push($words, '[...]'); array_push($words, $excerpt_more);
$text = implode(' ', $words); $text = implode(' ', $words);
} }
} }