Skip to content

Commit

Permalink
Update index.php
Browse files Browse the repository at this point in the history
  • Loading branch information
carolinan committed Jan 4, 2023
1 parent 0b7f3b3 commit 834c0cf
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) ) );
Expand All @@ -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 );
Expand Down

1 comment on commit 834c0cf

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Flaky tests detected.
Some tests passed with failed attempts. The failures may not be related to this commit but are still reported for visibility. See the documentation for more information.

🔍 Workflow run URL: https://github.com/WordPress/gutenberg/actions/runs/3837580378
📝 Reported issues:

Please sign in to comment.