The WPFolks app is out on iPhone and Android. Free, no ads. Download on the App Store Get it on Google Play
Skip to main content
Login Join
Snippet · PHP

Add a Custom Excerpt Length to WordPress Posts

Shared by Amit Dholiya · October 1, 2026 · @excerpt_length

8 views
1 upvote
Back to Snippets

Steps

  1. Add the PHP code to your theme’s functions.php.
  2. Change 25 to the number of words you want.
  3. Save the changes.
  4. WordPress will use the new length for automatically generated excerpts.
/**
 * Change the default WordPress excerpt length
 */
function custom_excerpt_length( $length ) {
    return 25;
}

add_filter( 'excerpt_length', 'custom_excerpt_length', 999 );

Tested on

WordPress 6.8

Reported by the author on October 1, 2026. WPFolks has not verified this.

Not tested against WordPress 7.1.3. It may still work.

Know a different way to do this? Add your approach as a variation so folks can compare them side by side.
Submit a variation

0 comments