Skip to content

Content

Change the automatic excerpt length

Easy functions.php

Changes generated excerpts to 28 words and replaces the default ending with an ellipsis.

Change 28 to the required number of words.

Useful for: Blog cards, archives and search results

functions.php
/**
 * Change the automatic WordPress excerpt length.
 */
function hmr_custom_excerpt_length( int $length ): int {
    return 28;
}
add_filter( 'excerpt_length', 'hmr_custom_excerpt_length', 999 );

/**
 * Change the automatic excerpt ending.
 */
function hmr_custom_excerpt_more( string $more ): string {
    return '…';
}
add_filter( 'excerpt_more', 'hmr_custom_excerpt_more' );