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_excerpt string — 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

Group wizard

One session: this hook, then each related_hooks entry. Walk it and tell us what to change.

the_excerpt → excerpt_length → the_content

functions.php — the_excerpt
functions.php
PHP the_excerpt · Hook 1 of 3 · Step 1 of 6

Practice the the_excerpt WordPress filter hook in our interactive sandbox — a VS Code-style editor with a step-by-step the_excerpt tutorial, add_filter exercises, and instant feedback. No local WordPress install required.