By default, WordPress sets the excerpt length to 55 words. That might work fine for some themes, but if you’re designing or…
By default, WordPress sets the excerpt length to 55 words. That might work fine for some themes, but if you’re designing or customizing your own layout, chances are you’ll want more control over how much content is shown in archive pages, post grids, or custom loops.

In this quick tutorial, you’ll learn how to change the excerpt length globally using a simple PHP code snippet—without the need for a plugin.
🔧 Why Change the Excerpt Length?
Adjusting the excerpt length can help:
- Keep your blog layout clean and consistent
- Avoid large or uneven text blocks in grids
- Improve readability and click-through rates
- Match your theme’s aesthetic or design guidelines
✅ The Code: Change Excerpt Length Site-Wide
To change the default excerpt length for all WordPress loops, add the following code to your theme’s functions.php
file or a custom plugin:
function custom_excerpt_length( $length ) {
return 25; // Change this number to whatever word count you want
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
📝 Explanation:
25
is the number of words shown in the excerpt.- This applies globally to
the_excerpt()
unless overridden by a theme or plugin.
📌 Optional: Customize the “Read More” Text
You can also change the [...]
that appears at the end of excerpts. Add this alongside the previous snippet:
function custom_excerpt_more( $more ) {
return '... <a href="' . get_permalink() . '">Read more</a>';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
This will append a clickable “Read more” link after each excerpt.
📦 Bonus: Use Custom Excerpts for Specific Post Types
If you only want to change the excerpt length for certain post types (like blog posts but not products), use conditional logic:
function custom_excerpt_length_by_post_type( $length ) {
if ( is_admin() ) return $length;
if ( get_post_type() === 'post' ) {
return 30;
} elseif ( get_post_type() === 'product' ) {
return 15;
}
return $length;
}
add_filter( 'excerpt_length', 'custom_excerpt_length_by_post_type' );
⚠️ Important Notes
- This only affects excerpts generated by
the_excerpt()
, notthe_content()
. - Some themes (like Astra, Kadence, or Divi) may override this setting—check your theme’s documentation if it doesn’t work.
- Always use a child theme or a custom plugin to avoid losing changes during updates.
🎯 Final Thoughts
With just a few lines of code, you can easily control the excerpt length site-wide and improve your blog’s visual harmony. Whether you’re building custom layouts or tweaking your existing theme, this small change can make a big UX difference.