diff --git a/packages/block-library/src/latest-posts/edit.js b/packages/block-library/src/latest-posts/edit.js
index 7aaf1b3ecf0ed..586ecc5943273 100644
--- a/packages/block-library/src/latest-posts/edit.js
+++ b/packages/block-library/src/latest-posts/edit.js
@@ -483,12 +483,17 @@ export default function LatestPostsEdit( { attributes, setAttributes } ) {
.split( ' ', excerptLength )
.join( ' ' ) }
{ createInterpolateElement(
- /* translators: excerpt truncation character, default … */
- __( ' … Read more' ),
+ sprintf(
+ /* translators: 1: The static string "Read more", 2: The post title only visible to screen readers. */
+ __( '… %1$s: %2$s' ),
+ __( 'Read more' ),
+ titleTrimmed || __( '(no title)' )
+ ),
{
a: (
// eslint-disable-next-line jsx-a11y/anchor-has-content
),
+ span: (
+
+ ),
}
) }
>
diff --git a/packages/block-library/src/latest-posts/index.php b/packages/block-library/src/latest-posts/index.php
index 356ba5032689f..d5f759c0c0e25 100644
--- a/packages/block-library/src/latest-posts/index.php
+++ b/packages/block-library/src/latest-posts/index.php
@@ -48,14 +48,6 @@ function render_block_core_latest_posts( $attributes ) {
$block_core_latest_posts_excerpt_length = $attributes['excerptLength'];
add_filter( 'excerpt_length', 'block_core_latest_posts_get_excerpt_length', 20 );
- $filter_latest_posts_excerpt_more = static function ( $more ) use ( $attributes ) {
- $use_excerpt = 'excerpt' === $attributes['displayPostContentRadio'];
- /* translators: %1$s is a URL to a post, excerpt truncation character, default … */
- return $use_excerpt ? sprintf( __( ' … Read more' ), esc_url( get_permalink() ) ) : $more;
- };
-
- add_filter( 'excerpt_more', $filter_latest_posts_excerpt_more );
-
if ( ! empty( $attributes['categories'] ) ) {
$args['category__in'] = array_column( $attributes['categories'], 'id' );
}
@@ -151,6 +143,24 @@ function render_block_core_latest_posts( $attributes ) {
$trimmed_excerpt = get_the_excerpt( $post );
+ /*
+ * Adds a "Read more" link with screen reader text.
+ * […] is the default excerpt ending from wp_trim_excerpt() in Core.
+ */
+ if ( str_ends_with( $trimmed_excerpt, ' […]' ) ) {
+ $excerpt_length = (int) apply_filters( 'excerpt_length', $block_core_latest_posts_excerpt_length );
+ if ( $excerpt_length <= $block_core_latest_posts_excerpt_length ) {
+ $trimmed_excerpt = substr( $trimmed_excerpt, 0, -11 );
+ $trimmed_excerpt .= sprintf(
+ /* translators: 1: A URL to a post, 2: The static string "Read more", 3: The post title only visible to screen readers. */
+ __( '… %2$s: %3$s' ),
+ esc_url( $post_link ),
+ __( 'Read more' ),
+ esc_html( $title )
+ );
+ }
+ }
+
if ( post_password_required( $post ) ) {
$trimmed_excerpt = __( 'This content is password protected.' );
}