Issue with Aria-label within the Read More Label

Hello, I am reaching out regarding the Aria-label within the Read more label on the homepage to comply with the Accessibility rules in Lighthouse.

I came across the following code in other support topics:

add_filter( 'generate_excerpt_more_output', function() {
  return sprintf(
    ' ... <a title="%1$s" class="read-more" href="$s" aria-label="%4$s">%3$s</a>',
    the_title_attribute( 'echo=0' ),
    esc_url( get_permalink( get_the_ID() ) ),
    __( 'Read more', 'generatepress' ),
      /* translators: Aria-label describing the read more button */
      _x( 'Read more on %s', 'more on post title', 'generatepress' ),
      the_title_attribute( 'echo=0' )

I found that this code indeed changes the Aria-label within the Read more label. However, when I add the tag


after the first paragraph of each article, the code stops working.

The HTML on the homepage appears as follows:

<p class="read-more-container">
<a title="[post-title]" class="read-more content-read-more" href="[post-url]" aria-label="More on [post-title]">Read more</a>

It appears that the Class has changed to class=”read-more content-read-more” instead of the original class=”read-more”. How can I modify the code to make it work for both the original class=”read-more” and the new class=”read-more content-read-more” so that both types of Read more labels are effective?

Thank you.


This site will teach you how to build a WordPress website for beginners. We will cover everything from installing WordPress to adding pages, posts, and images to your site. You will learn how to customize your site with themes and plugins, as well as how to market your site online.

Buy WordPress Transfer