“Read more” link after excerpts
Automatic excerpts end with a “Read more” link to the post instead of […].
<?php
add_filter(
'excerpt_more',
static function () {
$post = get_post();
if ( ! $post ) {
return '…';
}
return '… <a class="more-link" href="' . esc_url( get_permalink( $post ) ) . '">' . esc_html__( 'Read more' ) . '<span class="screen-reader-text"> ' . esc_html( get_the_title( $post ) ) . '</span></a>';
},
20
);
Good to know
Block themes show excerpts with the Post Excerpt block, which has its own “more” text setting.
In these packs
- Posts and the editor: Make the block editor calmer and give pages excerpts, tags and categories.