-
Notifications
You must be signed in to change notification settings - Fork 4.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Read More block: add aria-label and screen reader text #45490
Changes from all commits
b89f5c6
83e2d93
7b55ab1
d98f6ad
676e477
7928e6f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,15 +19,22 @@ function render_block_core_read_more( $attributes, $content, $block ) { | |
} | ||
|
||
$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 | ||
); | ||
$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( | ||
'<a %1s href="%2s" target="%3s">%4s</a>', | ||
'<a %1s href="%2s" target="%3s">%4s<span class="screen-reader-text">%5s</span></a>', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. There needs to be a space between the visible link text and the hidden text, otherwise the words will be pasted together. e.g. See the space inside the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make "grammatical" sense in cases where the user has customized the "read more" text, I went with the following format:
Does that make sense? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Great. Also good for internationalization. |
||
$wrapper_attributes, | ||
get_the_permalink( $post_ID ), | ||
esc_attr( $attributes['linkTarget'] ), | ||
$more_text | ||
$more_text, | ||
$screen_reader_text | ||
); | ||
} | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We received this feedback related to this change https://core.trac.wordpress.org/ticket/57471#comment:27
Basically we should avoid concatenation when it comes to translated strings.
Let's make sure to follow-up on that and label the PR with the "backport to WP beta/RC" label to include on the next package update in core.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tracked here #47812