How To Change The Excerpt Length And Read More Text In WordPress
WordPress shows 55 words in excerpts by default and ends them with […]. Two filters let you change both.
Change the excerpt length
function lotgrafix_excerpt_length( $length ) {
return 25;
}
add_filter( 'excerpt_length', 'lotgrafix_excerpt_length', 999 );
The high priority number makes sure your filter runs after the theme and the plugins.
Change the ending of the excerpt
function lotgrafix_excerpt_more( $more ) {
return '…';
}
add_filter( 'excerpt_more', 'lotgrafix_excerpt_more' );
Add a Read More link
function lotgrafix_excerpt_read_more( $more ) {
return '… <a class="lotgrafix-more" href="' . esc_url( get_permalink() ) . '">' . esc_html__( 'Read more', 'lotgrafix' ) . '</a>';
}
add_filter( 'excerpt_more', 'lotgrafix_excerpt_read_more' );
Trim any text to a number of words
Use this when you want a custom length in one specific place, without changing the global setting.
echo wp_trim_words( strip_shortcodes( get_the_content() ), 30, '…' );
Enable excerpts on pages
function lotgrafix_page_excerpts() {
add_post_type_support( 'page', 'excerpt' );
}
add_action( 'init', 'lotgrafix_page_excerpts' );
Notes
- If an author writes a manual excerpt,
excerpt_lengthdoes not apply to it. - For Chinese, Japanese and Korean sites, WordPress counts characters instead of words.


