Skip to content

WPShout Newsletter

Sign up for news, tips, and insights to help you build better websites.

Newsletter - Top banner

WordPress Post Excerpts: How They Work and How to Customize Them

WordPress post excerpts are the short previews that help readers decide what to open next. They can be written by hand, generated from post content, or shaped by the editor and theme. The important choice comes first: do you need a deliberate summary, or a consistent automatic preview?

This guide explains the difference, the Post Excerpt block, classic template functions, and safe ways to customize automatic output. It also keeps the familiar WordPress edge cases in view, because an excerpt that is technically short but inaccessible or cut through a tag is not much of a win.

WPShout featured graphic for manual, automatic, and customized WordPress post excerpts

Choose your excerpt path

A manual excerpt is the right choice when the opening needs a particular promise, tone, or context. It takes precedence over generated output. WordPress does not then trim that text through the automatic length filter or append the automatic continuation text. A short, edited summary is often better for a product archive, a course catalog, or a series where every card needs the same kind of introduction. In the block editor, open the Excerpt control from Post settings, enter the summary, and save the post. That value stays distinct from the opening paragraph, so changing one does not silently rewrite the other.

When there is no manual excerpt, WordPress can derive one from the post content through its automatic trimming path. wp_trim_excerpt() supplies that fallback. [1] get_the_excerpt() returns the manual value when one exists and otherwise passes through that automatic path. [2] That means a theme can use one template call while authors still retain editorial control.

WordPress 7.0 editor dialog for entering a manual post excerpt
WordPress 7.0.4 opens the manual Excerpt field in a dialog from the post settings panel.

Automatic excerpts are usually the practical default for a large archive. Core removes unsuitable block markup and trims the remaining text to a default of 55 words. If a reader needs a specific introduction, write a manual excerpt instead of trying to make a filter guess the intent.

The Post Excerpt block and editor controls

In a block theme, the Post Excerpt block displays a post preview inside a Query Loop or Post Template. Its settings can control the excerpt length, the more text, and whether the more text appears on a new line. [3] Query Loop documentation supplies the surrounding template context. [4] These are presentation settings for that block, so check the template where the archive output is actually assembled.

The editor’s excerpt documentation distinguishes a hand-written summary from text WordPress derives from the post body. [5] The Page/Post Settings Sidebar documentation describes the post-level control. [6] In WordPress 7.0.4, selecting Add an excerpt or Edit excerpt opens the field in a dialog. Interface labels can move, so use the documentation and the screen in front of you together.

WordPress 7.0 Post Excerpt block settings for link placement and word count
WordPress 7.0.4 Post Excerpt settings inside a Query Loop, with custom read-more text, a new-line toggle, and a 32-word limit.

Do not confuse this with the More block. More marks a break in a post’s full-content flow. It does not become an automatic excerpt rule, and it can be ignored when a theme is displaying excerpt cards. [7] In a Query Loop, the Post Excerpt block and its settings are the relevant controls.

Classic templates: the function you call matters

the_excerpt() echoes the excerpt for template output. [8] get_the_excerpt() returns it, which is what you need when composing a card, passing text to another function, or testing the value before display. Keep the distinction visible in custom templates: echoing the return value twice is just as confusing as forgetting to output it.

For classic themes, a template can call the_excerpt() inside the Loop and let core resolve manual or automatic content. For block themes, the Post Excerpt block usually owns that presentation decision. The same editorial rule still applies: a manual excerpt wins.

That distinction also helps when a preview is assembled outside the visible loop. Fetch the value with get_the_excerpt( $post ), then pass it through the normal escaping and markup rules for the component that will display it. Avoid reaching for get_the_content() just to imitate an excerpt. Full content may contain blocks, embeds, shortcodes, or author-controlled HTML that needs a different rendering path. A template should ask the excerpt API for an excerpt, not rebuild core’s work with a string operation.

Quick decision table

NeedUseWhy
One deliberate summaryManual excerptIt takes precedence and is not automatically trimmed.
Consistent archive previewsAutomatic excerpt or Post Excerpt blockCentralize length and continuation presentation.
Template outputthe_excerpt()Echoes the filtered value in the loop.
Value for another operationget_the_excerpt()Returns the value without echoing it.
Full-content breakMore blockIt is a separate editorial boundary, not an excerpt filter.

Safe recipes for automatic excerpts

Keep customization narrow and prefix every callback. Put filters in a small site plugin or a child theme’s functions.php, then lint and test them before deployment. The first two snippets affect the automatic path, not a manual excerpt.

To change the automatic word limit, use the excerpt_length filter. [9] A function that returns a small integer is easier to reason about than code that edits the whole post body:

<?php
add_filter( 'excerpt_length', 'wpshout_excerpt_length' );
function wpshout_excerpt_length( $length ) {
    return 35;
}Code language: HTML, XML (xml)

This changes automatic excerpts wherever the filter runs. It does not shorten a manual excerpt or override a Post Excerpt block’s own length control. The deeper guide to changing WordPress excerpt length traces the filter through core.

For ordinary Loop output, the excerpt_more hook is a bounded extension point. [10] Return an accessible same-tab link, and escape the URL, visible label, and title at output:

<?php
add_filter( 'excerpt_more', 'wpshout_excerpt_more' );
function wpshout_excerpt_more( $more ) {
    $post = get_post();
    if ( ! $post ) {
        return $more;
    }

    return sprintf(
        ' <a class="more-link" href="%1$s">%2$s<span class="screen-reader-text">: %3$s</span></a>',
        esc_url( get_permalink( $post ) ),
        esc_html__( 'Continue reading', 'wpshout' ),
        esc_html( get_the_title( $post ) )
    );
}Code language: HTML, XML (xml)

The hook passes only the continuation string, not the post being excerpted. This callback therefore uses the current global post and is limited to normal Loop output. When a card calls get_the_excerpt( $post ) for a non-global post, build its link outside this filter with get_permalink( $post ) and get_the_title( $post ).

Word and character trimming

If a feature needs an arbitrary string rather than the current post excerpt, wp_trim_words() is the word-aware option. [11] It is useful for a card label or a custom summary where the input is already known. Do not feed it untrusted HTML and assume it will preserve every tag boundary.

<?php
$source_text = 'A deliberately supplied summary for a small card that continues beyond twenty words so the function trims the remaining copy instead of returning it unchanged.';
$summary = wp_trim_words(
    $source_text,
    20,
    '…'
);Code language: HTML, XML (xml)

For a character ceiling on text that may contain markup, wp_html_excerpt() strips tags and truncates without splitting UTF-8 characters or HTML entities. [12] It returns text, not preserved HTML structure:

<?php
$source_html = '<p>A deliberately supplied summary with <strong>markup</strong> and enough additional text to exceed the character limit safely.</p>';
$summary = wp_html_excerpt( $source_html, 59, '…' );Code language: HTML, XML (xml)

Budget the optional suffix separately: a 59-character body plus the one-character ellipsis can fit a 60-character component. If the input is shorter than the limit, the function returns it unchanged and does not append the suffix. Choose word trimming for readable previews and character trimming only when the design truly requires a fixed character budget.

Core’s excerpt_remove_blocks() exists for the automatic path because block markup is not prose. [13] That is another reason to avoid grabbing raw global content and cutting it with byte-based substr(). The old shortcut can split a multibyte character, leave markup open, or expose content that the excerpt pipeline would have removed.

Troubleshooting and checklist

If a length filter appears to do nothing, check for a manual excerpt first. If the editor shows a different result from the archive, inspect the template: a Post Excerpt block may have its own length and more-text settings. If a More block seems ineffective, confirm that the theme is displaying excerpts rather than the full post. Finally, check whether a plugin has added another filter, and test with a plain post before changing several hooks at once. Compare a post with a manual summary, a post without one, and a post containing formatted blocks so each branch is tested.

Separate saved data from template output while testing. A manual excerpt can exist even when the active template displays a Post Content block instead. The reverse is also true: shortening one Post Excerpt block changes that template’s presentation without rewriting the excerpt stored on the post. Inspect the active template before editing post data or adding another filter.

  • Use a manual excerpt for an intentional summary.
  • Use the automatic path for a consistent fallback.
  • Use the Post Excerpt block for block-template presentation.
  • Use the_excerpt() to echo and get_the_excerpt() to return.
  • Prefer word-aware or UTF-8-safe, tag-stripped trimming over byte-based slicing.
  • Escape URLs, titles, and visible link text at output.
  • Lint every PHP snippet and test both manual and automatic posts.

The core filter registration is worth remembering: wp_trim_excerpt() is attached to get_the_excerpt at priority 10 and accepts two arguments in the default filters. [14] That explains the ordinary automatic behavior, but it does not make every theme or plugin output identical. Start by identifying which path renders the card, then customize the smallest layer that owns the result.

References

  1. [1] WordPress Developer Resources: wp_trim_excerpt().
  2. [2] WordPress Developer Resources: get_the_excerpt().
  3. [3] WordPress.org: Post Excerpt block.
  4. [4] WordPress Developer Resources: Extending the Query Loop block.
  5. [5] WordPress.org: What is an Excerpt?.
  6. [6] WordPress.org: Page/Post Settings Sidebar.
  7. [7] WordPress.org: More block.
  8. [8] WordPress Developer Resources: the_excerpt().
  9. [9] WordPress Developer Resources: excerpt_length.
  10. [10] WordPress Developer Resources: excerpt_more.
  11. [11] WordPress Developer Resources: wp_trim_words().
  12. [12] WordPress Developer Resources: wp_html_excerpt().
  13. [13] WordPress Developer Resources: excerpt_remove_blocks().
  14. [14] WordPress develop: default-filters.php.
Yay! 🎉 You made it to the end of the article!
WPShout Editorial
Share:

1 Comment
Most Voted
Newest Oldest
David Ganz
May 13, 2019 2:18 am

Well Done!
Thanks