Archived topic
Add post title to Read more link on Archive pages
5 replies · Started by Klaus on July 26, 2022
For usability and SEO purposes, I would like to adjust the Read more label on my archive pages and include the post title for each post:

How can I achieve this? I suppose I can work with a shortcode?
FYI: I use the code snippet plugin to add PHP code.
Thanks and best regards,
Klaus
Hi Klaus,
One approach is through a PHP snippet like this:
add_filter('generate_excerpt_more_output', function($output){
return $output . ' ' . get_the_title();
}, 10);
This appends the title to the read more button.
Hope this helps!
Thanks Fernando, this now shows the read more label as follows:
Read: Title of First Post
How do I make it so that the link is extended to the post title?
Hi there,
try this snippet instead:
add_filter('generate_excerpt_more_output', function($output){
return sprintf(
' ... <a title="%1$s" class="read-more" href="%2$s" aria-label="%4$s">%3$s %1$s</a>',
the_title_attribute( 'echo=0' ),
esc_url( get_permalink( get_the_ID() ) ),
__( 'Read ', 'generatepress' ),
sprintf(
/* translators: Aria-label describing the read more button */
_x( 'More on %s', 'more on post title', 'generatepress' ),
the_title_attribute( 'echo=0' )
)
);
}, 10);
Great, this worked.
Thanks David :)
You're welcome