[Resolved] Add post title to Read more link on Archive pages

Home Forums Support [Resolved] Add post title to Read more link on Archive pages

Home Forums Support Add post title to Read more link on Archive pages

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2293691
    Klaus

    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 to Adjust Read More Label?

    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

    #2293714
    Fernando
    Customer Support

    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!

    #2293738
    Klaus

    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?

    Read: Title of First Post

    #2293757
    David
    Staff
    Customer Support

    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); 
    #2293787
    Klaus

    Great, this worked.

    Thanks David 🙂

    #2293799
    David
    Staff
    Customer Support
Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.