From b89f5c63a64f613c0f285c26c263ff9d3b76a6d5 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Wed, 2 Nov 2022 10:43:13 -0400 Subject: [PATCH 1/6] Add aria label + screen reader text to the link. --- packages/block-library/src/read-more/index.php | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/read-more/index.php b/packages/block-library/src/read-more/index.php index 93013b2517d14..b9770b3b5ba0a 100644 --- a/packages/block-library/src/read-more/index.php +++ b/packages/block-library/src/read-more/index.php @@ -19,15 +19,18 @@ function render_block_core_read_more( $attributes, $content, $block ) { } $post_ID = $block->context['postId']; + $post_title = get_the_title( $post_ID ); $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); return sprintf( - '%4s', + '%5s%6s', $wrapper_attributes, get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), - $more_text + esc_attr__( 'Post ID: ' . $post_ID ), + $more_text, + $post_title ); } From 83e2d93be43e033511ca02c0cb7d9b8567b6361b Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Thu, 3 Nov 2022 12:23:40 -0400 Subject: [PATCH 2/6] Use only screen reader text. --- packages/block-library/src/read-more/index.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/read-more/index.php b/packages/block-library/src/read-more/index.php index b9770b3b5ba0a..467c12677a1ae 100644 --- a/packages/block-library/src/read-more/index.php +++ b/packages/block-library/src/read-more/index.php @@ -19,18 +19,17 @@ function render_block_core_read_more( $attributes, $content, $block ) { } $post_ID = $block->context['postId']; - $post_title = get_the_title( $post_ID ); + $screen_reader_text = __( 'Read more about ' ) . get_the_title( $post_ID ); $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); return sprintf( - '%5s%6s', + '%4s%5s', $wrapper_attributes, get_the_permalink( $post_ID ), esc_attr( $attributes['linkTarget'] ), - esc_attr__( 'Post ID: ' . $post_ID ), $more_text, - $post_title + $screen_reader_text ); } From 7b55ab1fbeaf8e3aa9dea30211405547a1a0095d Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Fri, 4 Nov 2022 13:37:57 -0400 Subject: [PATCH 3/6] Make the screen reader text more universal. --- packages/block-library/src/read-more/index.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/packages/block-library/src/read-more/index.php b/packages/block-library/src/read-more/index.php index 467c12677a1ae..8c463e05f84f0 100644 --- a/packages/block-library/src/read-more/index.php +++ b/packages/block-library/src/read-more/index.php @@ -19,7 +19,12 @@ function render_block_core_read_more( $attributes, $content, $block ) { } $post_ID = $block->context['postId']; - $screen_reader_text = __( 'Read more about ' ) . get_the_title( $post_ID ); + $post_title = get_the_title( $post_ID ); + /* translators: %s is either the post title or post ID to describe the link for screen readers. */ + $screen_reader_text = sprintf( + __( ': %s' ), + $post_title !== '' ? $post_title : __( 'post ' ) . $post_ID + ); $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); $more_text = ! empty( $attributes['content'] ) ? wp_kses_post( $attributes['content'] ) : __( 'Read more' ); From d98f6adca83a9ac156341a0ebb271d106d5f9c12 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Mon, 7 Nov 2022 14:55:14 -0700 Subject: [PATCH 4/6] Make the screen reader text explicit when the post is untitled. --- packages/block-library/src/read-more/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/block-library/src/read-more/index.php b/packages/block-library/src/read-more/index.php index 8c463e05f84f0..97ce943eb5677 100644 --- a/packages/block-library/src/read-more/index.php +++ b/packages/block-library/src/read-more/index.php @@ -23,7 +23,7 @@ function render_block_core_read_more( $attributes, $content, $block ) { /* translators: %s is either the post title or post ID to describe the link for screen readers. */ $screen_reader_text = sprintf( __( ': %s' ), - $post_title !== '' ? $post_title : __( 'post ' ) . $post_ID + $post_title !== '' ? $post_title : __( 'untitled post ' ) . $post_ID ); $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) ); From 676e477b39ce1f6cf75882ce3b20557682da57f5 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Wed, 9 Nov 2022 10:24:41 -0700 Subject: [PATCH 5/6] Make linter happy. --- packages/block-library/src/read-more/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/read-more/index.php b/packages/block-library/src/read-more/index.php index 97ce943eb5677..1aef66099352b 100644 --- a/packages/block-library/src/read-more/index.php +++ b/packages/block-library/src/read-more/index.php @@ -18,8 +18,8 @@ function render_block_core_read_more( $attributes, $content, $block ) { return ''; } - $post_ID = $block->context['postId']; - $post_title = get_the_title( $post_ID ); + $post_ID = $block->context['postId']; + $post_title = get_the_title( $post_ID ); /* translators: %s is either the post title or post ID to describe the link for screen readers. */ $screen_reader_text = sprintf( __( ': %s' ), From 7928e6f0a408525e2f0b5d6619f16677a72dc850 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Wed, 9 Nov 2022 10:43:27 -0700 Subject: [PATCH 6/6] Move translators note and fix Yoda. --- packages/block-library/src/read-more/index.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/block-library/src/read-more/index.php b/packages/block-library/src/read-more/index.php index 1aef66099352b..7bfd22e6d4c4d 100644 --- a/packages/block-library/src/read-more/index.php +++ b/packages/block-library/src/read-more/index.php @@ -18,12 +18,12 @@ function render_block_core_read_more( $attributes, $content, $block ) { return ''; } - $post_ID = $block->context['postId']; - $post_title = get_the_title( $post_ID ); - /* translators: %s is either the post title or post ID to describe the link for screen readers. */ + $post_ID = $block->context['postId']; + $post_title = get_the_title( $post_ID ); $screen_reader_text = sprintf( + /* translators: %s is either the post title or post ID to describe the link for screen readers. */ __( ': %s' ), - $post_title !== '' ? $post_title : __( 'untitled post ' ) . $post_ID + '' !== $post_title ? $post_title : __( 'untitled post ' ) . $post_ID ); $justify_class_name = empty( $attributes['justifyContent'] ) ? '' : "is-justified-{$attributes['justifyContent']}"; $wrapper_attributes = get_block_wrapper_attributes( array( 'class' => $justify_class_name ) );