- This topic has 3 replies, 2 voices, and was last updated 3 years, 3 months ago by
Fernando.
-
AuthorPosts
-
February 1, 2023 at 11:50 pm #2518076
Rachel
Hi there,
I use the following snippet for the excerpt read more text. However I am getting warnings as there is no aria-label associated with the read more link. Is there a way to adjust this snippet to add an aria-label for the read more link text?
I assume the standard would be to include the title of the post in the aria-label?
Thanks,
Racheladd_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;if ( has_excerpt() && ! is_feed() ) {
$output = sprintf( ‘%1$s %3$s‘,
$excerpt,
get_permalink(),
__( ‘Read more’, ‘generatepress’ )
);
}return $output;
}February 2, 2023 at 12:34 am #2518127Fernando Customer Support
Hi Rachel,
Can you try this code instead?:
add_filter( 'wp_trim_excerpt', 'tu_excerpt_metabox_more' ); function tu_excerpt_metabox_more( $excerpt ) { $output = $excerpt; if ( has_excerpt() ) { $output = sprintf( '%1$s <a href="%2$s" aria-label="%4$s">%3$s</a>', $excerpt, get_permalink(), __( 'Read more', 'generatepress' ), sprintf( /* translators: Aria-label describing the read more button */ _x( 'Read more of the post %s', 'more on post title', 'generatepress' ), the_title_attribute( 'echo=0' ) ) ); } return $output; }February 2, 2023 at 8:48 pm #2519534Rachel
Hi Fernando
Great – that has worked, thank you.I just modified your code slightly to include my exclusion of the read more text from the RSS feed, as was in the original code.
Cheers,
Racheladd_filter( ‘wp_trim_excerpt’, ‘tu_excerpt_metabox_more’ );
function tu_excerpt_metabox_more( $excerpt ) {
$output = $excerpt;if ( has_excerpt() && ! is_feed() ) {
$output = sprintf( ‘%1$s %3$s‘,
$excerpt,
get_permalink(),
__( ‘Read more’, ‘generatepress’ ),
sprintf(
/* translators: Aria-label describing the read more button */
_x( ‘Read more of the post %s’, ‘more on post title’, ‘generatepress’ ),
the_title_attribute( ‘echo=0’ )
)
);
}return $output;
}February 2, 2023 at 9:21 pm #2519552Fernando Customer Support
You’re welcome, Rachel!
-
AuthorPosts
- You must be logged in to reply to this topic.