Descriptive "Read More" Links With the Post Title
Adds the post title as hidden text to "Read more" and "Continue reading" links, so screen reader users hear where each link goes instead of a list of identical links.
Opens WPIDE on
Code
// Visible link text; the post title is appended as hidden text.
$wpide_more_text = 'Read more';
$wpide_more_link = function () use ( $wpide_more_text ) {
return sprintf(
' <a class="more-link" href="%1$s">%2$s<span class="screen-reader-text"> about %3$s</span></a>',
esc_url( get_permalink() ),
esc_html( $wpide_more_text ),
esc_html( get_the_title() )
);
};
add_filter( 'excerpt_more', function () use ( $wpide_more_link ) {
return '…' . $wpide_more_link();
}, 20 );
add_filter( 'the_content_more_link', function () use ( $wpide_more_link ) {
return $wpide_more_link();
}, 20 );
Notes
Change $wpide_more_text to the visible wording you want; the post title is added for screen readers only.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.