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="https://projectdmc.org/support/topic/issue-with-aria-label-within-the-read-more-label/%2$s" aria-label="%4$s">%3$s</a>',
the_title_attribute( 'echo=0' ),
esc_url( get_permalink( get_the_ID() ) ),
__( 'Read more', 'generatepress' ),
sprintf(
/* 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
<!--more-->
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>
</p>
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.