I know this is a really old thread, but I just struggled with this problem and none of the solutions I found on the Internet worked correctly for me. First, my own excerpt_more filter has always been cut off.
The way I decided is ugly, but this is the only working solution I could find. The ugliness involves modifying the 4 lines of the WP kernel (!!) + using another global variable (although WP already does this so that I don't feel too bad).
I changed wp_trim_excerpt to wp-includes / formatting.php:
<?php function wp_trim_excerpt($text = '') { global $excerpt_length; $len = $excerpt_length > 0 ? $excerpt_length : 55; $raw_excerpt = $text; if ( '' == $text ) { $text = get_the_content(''); $text = strip_shortcodes( $text ); $text = apply_filters('the_content', $text); $text = str_replace(']]>', ']]>', $text); $excerpt_length = apply_filters('excerpt_length', $len); $excerpt_more = apply_filters('excerpt_more', ' ' . '[…]'); $text = wp_trim_words( $text, $excerpt_length, $excerpt_more ); } $excerpt_length = null; return apply_filters('wp_trim_excerpt', $text, $raw_excerpt); }
The only new material is the $excerpt_length and $len bits.
Now, if I want to change the default length, I do this in my template:
<?php $excerpt_length = 10; the_excerpt() ?>
Changing the kernel is a terrible decision, so I would like to know if someone comes up with something better.
powerbuoy Aug 30 '13 at 0:19 2013-08-30 00:19
source share