WordPress generates excerpts by default using the first 55 words of post content. You can override this globally or per-post type by adding filters to your theme or a must-use plugin.
Basic excerpt length filter
Add this to wp-content/themes/your-theme/functions.php:
function custom_excerpt_length( $length ) {
return 35;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
Replace 35 with your desired word count. This filter affects all auto-generated excerpts produced by the_excerpt() calls.
Important: This only applies to excerpts WordPress generates from post content. If you’ve manually set an excerpt in the post editor’s “Excerpt” field, WordPress uses that instead and ignores this filter.
Different excerpt lengths by post type or page
Use conditional logic to apply different lengths in different contexts:
function custom_excerpt_length( $length ) {
if ( is_admin() ) {
return $length;
}
if ( is_home() || is_archive() ) {
return 30;
}
if ( is_singular( 'post' ) ) {
return 50;
}
if ( is_singular( 'page' ) ) {
return 75;
}
return $length;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
This returns 30 words on home and archive pages, 50 on single posts, and 75 on pages. Adjust the conditionals based on your site structure.
Customize the excerpt ending
WordPress appends [...] by default when an excerpt is truncated. Change this with the excerpt_more filter:
function custom_excerpt_more( $more ) {
return ' <a href="' . get_permalink() . '">Read more →</a>';
}
add_filter( 'excerpt_more', 'custom_excerpt_more' );
This replaces the ellipsis with a “Read more” link that points to the full post.
Using a child theme
If you’re using a third-party theme, create a child theme to protect your customizations during theme updates:
- Create the directory:
wp-content/themes/your-theme-child/ - Create
style.csswith a header identifying the parent:
/*
Theme Name: Your Theme Child
Template: your-theme
*/
- Create
functions.php:
<?php
add_action( 'wp_enqueue_scripts', 'enqueue_child_theme_styles' );
function enqueue_child_theme_styles() {
wp_enqueue_style( 'parent-theme', get_template_directory_uri() . '/style.css' );
wp_enqueue_style( 'child-theme', get_stylesheet_uri() );
}
function custom_excerpt_length( $length ) {
return 35;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
Must-use plugins for persistent customizations
For critical customizations that should survive theme changes, use a must-use (MU) plugin instead. MU plugins load before regular plugins and themes:
- Create
wp-content/mu-plugins/excerpt-length.php - Add your filter code:
<?php
function custom_excerpt_length( $length ) {
return 35;
}
add_filter( 'excerpt_length', 'custom_excerpt_length' );
MU plugins are ideal for site-critical functionality that shouldn’t depend on theme or plugin activation state.
Generate excerpts programmatically
For complex scenarios where filters aren’t enough, generate excerpts in your templates directly:
<?php
$excerpt = wp_trim_words( get_the_content(), 30, '... <a href="' . get_permalink() . '">Continue reading</a>' );
echo wp_kses_post( $excerpt );
wp_trim_words() returns exactly 30 words (adjustable) and lets you specify custom text at the end. Use wp_kses_post() to sanitize the HTML output safely.
Testing your changes
After implementing your filter:
- Check your homepage and archive pages to verify
the_excerpt()displays correctly - Confirm manually-set excerpts still work (they should bypass your filter)
- If using post-type conditionals, test each post type
- Clear any caching plugin’s cache
- Check the browser’s page source to ensure your custom “Read more” link appears

I just thought of how I may able to do this in WP, and here it is!
Thank you!