Skip to content

Early-bird lifetime licence: $199 once, for the first 200 buyers only. See the offer

excerpt_length

Sets how many words WordPress keeps when it creates an automatic excerpt from a post's content. The default is 55.

  • Type Filter
  • From WordPress
  • Since 2.7.0
  • Fired in wp-includes/formatting.php

When it fires

WordPress applies excerpt_length in wp_trim_excerpt() when a post has no manual excerpt and one has to be cut from the content. The Latest Posts block applies it too.

Excerpts typed into the Excerpt box are never shortened by this filter.

Parameters

Parameters
$numberint The maximum number of words. Default 55.

What to return

An integer: the number of words to keep.

Example: Use 30-word excerpts

PHP
add_filter( 'excerpt_length', function ( $number ) {
	return is_admin() ? $number : 30;
}, 20 );

Good to know

  • In block themes, the Post Excerpt block uses its own word limit setting and overrides this filter while it renders.
  • Use a priority above 10 if your theme sets its own excerpt length, so yours runs last.

Move your snippets over this afternoon.

Importing changes nothing until you switch over, and your old shortcodes keep working.