Filter Hook since 2.7.0

excerpt_length

Controls the auto-generated excerpt word count

Description

excerpt_length only affects auto excerpts, not the Excerpt box in the editor. Return an integer word count.

When it runs

When WordPress generates an excerpt from post content because no manual excerpt exists.

Signature

apply_filters( 'excerpt_length', int $number );

Parameters

  • $number int — Word count. Default 55.

Examples

Basic

add_filter( 'excerpt_length', function( $length ) {
    return 30;
} );

Show 30 words in generated excerpts.

Real case

add_filter( 'excerpt_length', function( $length ) {
    return is_search() ? 40 : 20;
} );

Vary excerpt length by context — longer on search results, shorter elsewhere.

Common Use Cases

  • Shorten excerpts for card layouts
  • Lengthen excerpts for search results
  • Vary length by post type
  • Control reading time estimates

Common mistakes

  • Expecting this filter to trim a manual excerpt — it does not

Related hooks

FAQ

Why did my excerpt_length change do nothing?

The post already has a manually written excerpt, or the theme calls a hardcoded wp_trim_words() instead of get_the_excerpt() — this filter only affects the auto-generation path.

Source: wp-includes/formatting.php

Group wizard

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

excerpt_length → the_content

functions.php — excerpt_length
functions.php
PHP excerpt_length · Hook 1 of 2 · Step 1 of 7

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