How to Change the Default WordPress Excerpt Length Per Post Type
WordPress excerpts are widely used in archives, search results, related posts, and custom listings. By default, WordPress limits excerpts to 55 words, regardless of post type.
In real projects, this is rarely ideal. Blog posts, custom post types, and landing-style content often need different excerpt lengths.
This article explains how to change the excerpt length safely per post type, without breaking themes or plugins.
How WordPress Handles Excerpts
There are two types of excerpts:
- Manual excerpts – written explicitly in the editor
- Automatic excerpts – generated from post content
The techniques below affect automatic excerpts only. Manual excerpts are never truncated.
The Default Excerpt Length
WordPress uses the excerpt_length filter to determine how many words to output.
add_filter( 'excerpt_length', function() {
return 55;
} );
We’ll extend this logic to apply different lengths depending on post type.
Change Excerpt Length Per Post Type (Recommended)
This is the most common and flexible approach.
add_filter( 'excerpt_length', function( $length ) {
if ( is_admin() ) {
return $length;
}
if ( is_singular() ) {
return $length;
}
$post_type = get_post_type();
switch ( $post_type ) {
case 'post':
return 40;
case 'product':
return 20;
case 'event':
return 30;
default:
return 55;
}
}, 10 );
Why These Checks Matter
is_admin()prevents side effects in the dashboardis_singular()avoids trimming full content viewsget_post_type()ensures accurate context
Change Excerpt Length Only on Archives
If you want excerpts customized only on archive-style pages:
add_filter( 'excerpt_length', function( $length ) {
if ( is_admin() ) {
return $length;
}
if ( is_post_type_archive( 'event' ) ) {
return 25;
}
if ( is_category() || is_tag() ) {
return 35;
}
return 55;
}, 10 );
This keeps single pages and other views untouched.
Change Excerpt Length for a Specific Custom Post Type
If you only need to target one CPT:
add_filter( 'excerpt_length', function( $length ) {
if ( is_admin() ) {
return $length;
}
if ( get_post_type() === 'news' ) {
return 25;
}
return $length;
}, 10 );
Control Excerpt Length Inside a Custom Loop
Sometimes global filters are too broad. In custom queries, you can override excerpt length locally.
add_filter( 'excerpt_length', 'my_temp_excerpt_length', 99 );
function my_temp_excerpt_length() {
return 20;
}
the_excerpt();
remove_filter( 'excerpt_length', 'my_temp_excerpt_length', 99 );
This approach is useful in:
- Related posts sections
- Sidebar widgets
- Custom blocks or shortcodes
Change the Excerpt “Read More” Text
Excerpt length and the trailing text often go together.
add_filter( 'excerpt_more', function( $more ) {
return '…';
} );
You can also make it contextual:
add_filter( 'excerpt_more', function( $more ) {
if ( get_post_type() === 'product' ) {
return '… View product';
}
return '… Read more';
} );
Common Mistakes to Avoid
- Forgetting to exclude
is_admin() - Applying excerpt filters on single post views
- Using
the_content()instead ofthe_excerpt() - Overusing global filters when local control is better
Where to Add This Code
- Best: Code Snippets plugin
- Also OK: Child theme
functions.php - Large projects: Custom utility plugin
Best Practices for Excerpt Length
- Short excerpts for dense listings (cards, grids)
- Longer excerpts for editorial archives
- Different lengths per post type improve readability
- Always prefer manual excerpts for critical content
Conclusion
Changing the default WordPress excerpt length per post type is a small tweak with a big UX impact. By using the excerpt_length filter carefully and contextually, you can tailor summaries to fit each content type perfectly.
Key takeaway:
Use global filters sparingly, respect context, and customize excerpts based on how content is actually displayed.
This approach keeps your theme clean, flexible, and scalable.
🎨 Want to learn more? Visit our WordPress Customization Hub for tips and advanced techniques.