class my_menu extends WP_Widget
{
function widget($args, $instance)
{
// Excerpt length filter
$new_excerpt_length = create_function('$length', "return " . $excerpt_length . ";");
if ( $instance["excerpt_length"] > 0 ) {
add_filter('excerpt_length', $new_excerpt_length, 999);
}
//...
}
}
This filter works great if the post does not have an excerpt. How do I apply the same filter to a post that has an excerpt?
In other words, when the post has an actual excerpt, its not filtering it at all, the whole excerpt is displayed. However, when the post does not have an excerpt, the get_the_excerpt() call gets filtered so that it only returns the number of words specified by “excerpt_length”
I posted an article about this a while ago: