Filter Hook since 0.71
the_excerpt
Filters the displayed post excerpt
Description
the_excerpt filters the final excerpt string, whether it was typed manually or auto-generated — use excerpt_length/excerpt_more to shape the auto version instead.
When it runs
When the_excerpt() runs in a template, after get_the_excerpt() and its own filters have resolved the string.
Signature
apply_filters( 'the_excerpt', string $post_excerpt );Parameters
$post_excerptstring — The post excerpt.
Examples
Basic
add_filter( 'the_excerpt', function( $excerpt ) {
return '<div class="excerpt-wrap">' . $excerpt . '</div>';
} );Wrap every displayed excerpt in a styling container.
Common Use Cases
- Wrap excerpts in custom markup
- Append a 'read more' link consistently
- Strip shortcodes left in excerpts
Common mistakes
- Expecting this filter to control excerpt length — that's excerpt_length, this one only touches the final string
Related hooks
FAQ
Does the_excerpt run for manually written excerpts too?
Yes — it runs regardless of whether the excerpt was typed in the editor or auto-generated from content.
Source: wp-includes/post-template.php