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"
wp_trim_excerpt
is applied toget_the_excerpt
. The filter should work. I am wondering if the problem isn't somewhere else in your code. That you are doing this inside a widget raises a flag, but it really depends on the code you chopped out of your post. Please include that. – s_ha_dum Dec 13 '12 at 21:03