From 834c0cf026ea82d3bebf5fc6992063bcf7cfbbf6 Mon Sep 17 00:00:00 2001 From: Carolina Nymark Date: Wed, 4 Jan 2023 12:02:04 +0100 Subject: [PATCH] Update index.php --- .../src/post-featured-image/index.php | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/block-library/src/post-featured-image/index.php b/packages/block-library/src/post-featured-image/index.php index 6762c14fe7bf58..e47ba78ee9216d 100644 --- a/packages/block-library/src/post-featured-image/index.php +++ b/packages/block-library/src/post-featured-image/index.php @@ -25,11 +25,11 @@ function render_block_core_post_featured_image( $attributes, $content, $block ) the_post(); } - $is_link = isset( $attributes['isLink'] ) && $attributes['isLink']; - $size_slug = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail'; - $attr = get_block_core_post_featured_image_border_attributes( $attributes ); - $overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes ); - $title = isset( $attributes['title'] ) ? $attributes['title'] : ''; + $is_link = isset( $attributes['isLink'] ) && $attributes['isLink']; + $size_slug = isset( $attributes['sizeSlug'] ) ? $attributes['sizeSlug'] : 'post-thumbnail'; + $attr = get_block_core_post_featured_image_border_attributes( $attributes ); + $overlay_markup = get_block_core_post_featured_image_overlay_element_markup( $attributes ); + $title_attribute = isset( $attributes['title'] ) ? $attributes['title'] : ''; if ( $is_link ) { $attr['alt'] = trim( strip_tags( get_the_title( $post_ID ) ) ); @@ -43,8 +43,15 @@ function render_block_core_post_featured_image( $attributes, $content, $block ) $attr['style'] = empty( $attr['style'] ) ? $extra_styles : $attr['style'] . $extra_styles; } - if ( $title ) { - $attr['title'] = trim( strip_tags( $title ) ); + /* + * If the image is linked and the target has a post title, + * keep the post title as the link text in the alt attribute, + * and do not output the title attribute. + * This is because the post title describes the link target, + * while the image title attribute describes the role of the image. + */ + if ( $title_attribute && ! ( $is_link && get_the_title( $post_ID ) ) ) { + $attr['title'] = trim( strip_tags( $title_attribute ) ); } $featured_image = get_the_post_thumbnail( $post_ID, $size_slug, $attr );