Skip to content

Commit

Permalink
Latest Posts: Add aria-label to featured links (#36251)
Browse files Browse the repository at this point in the history
* Add aria-label to featured links
* Move title var to top of foreach loop
* include title as aria-label content for each featured image link
  • Loading branch information
robin-scott committed Dec 24, 2021
1 parent 3e1d623 commit 6c15f2f
Showing 1 changed file with 7 additions and 5 deletions.
12 changes: 7 additions & 5 deletions packages/block-library/src/latest-posts/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@ function render_block_core_latest_posts( $attributes ) {

foreach ( $recent_posts as $post ) {
$post_link = esc_url( get_permalink( $post ) );
$title = get_the_title( $post );

if ( ! $title ) {
$title = __( '(no title)' );
}

$list_items_markup .= '<li>';

Expand All @@ -86,8 +91,9 @@ function render_block_core_latest_posts( $attributes ) {
);
if ( $attributes['addLinkToFeaturedImage'] ) {
$featured_image = sprintf(
'<a href="%1$s">%2$s</a>',
'<a href="%1$s" aria-label="%2$s">%3$s</a>',
$post_link,
$title,
$featured_image
);
}
Expand All @@ -98,10 +104,6 @@ function render_block_core_latest_posts( $attributes ) {
);
}

$title = get_the_title( $post );
if ( ! $title ) {
$title = __( '(no title)' );
}
$list_items_markup .= sprintf(
'<a href="%1$s">%2$s</a>',
$post_link,
Expand Down

0 comments on commit 6c15f2f

Please sign in to comment.