excerpt_more
Changes the text added to the end of a shortened automatic excerpt. By default it's ' […]'.
When it fires
WordPress applies excerpt_more in wp_trim_excerpt() when it builds an automatic excerpt from a post's content. What you return is added to the end of the text, but only if the text was actually cut short.
It isn't used for manual excerpts typed into the Excerpt box.
Parameters
$more_stringstring |
The string shown within the more link. |
|---|
What to return
The string to add after the excerpt. It can contain HTML, so escape anything you add.
Example: Replace […] with a Read more link
add_filter( 'excerpt_more', function () {
return sprintf(
'… <a class="read-more" href="%1$s">%2$s</a>',
esc_url( get_permalink() ),
esc_html__( 'Read more', 'my-snippets' )
);
} );
Good to know
- In block themes, if the Post Excerpt block has its own 'more' text set, the block replaces your output with nothing, so only one link shows.
- get_permalink() without an argument uses the current post, so this is meant for excerpts shown in the loop.