Custom excerpt length and read more link
- WordPress
WordPress defaults to a 55-word excerpt with a bare [...] suffix — too long for card layouts, and the suffix isn’t even linked to the full post. This customizes both.
<?php
/**
* Custom Excerpt Length and Read More
*
* WordPress defaults to a 55-word excerpt with a "[...]" suffix that isn't
* linked to anything. This snippet shortens the excerpt to 30 words (better
* for card layouts and archives) and replaces the suffix with a styled
* "Continue reading" link that points to the full post.
*
* Usage: Add to functions.php. Adjust the word count as needed.
*
* @category wordpress
* @language php
*
* @author Adame Dahmani https://adame.io
* @support Support my family project: https://adame.io/fundraiser
*/
add_filter( 'excerpt_length', function () {
return 30;
}, 999 );
add_filter( 'excerpt_more', function () {
return sprintf(
'… <a href="%s" class="read-more">Continue reading</a>',
esc_url( get_permalink() )
);
} );The 30-word limit works well for grid/card-based archive layouts. The ellipsis + “Continue reading” link gives users a clear action to take.