Skip to content

Commit

Permalink
Fix post featured image scaling on the front (#46838)
Browse files Browse the repository at this point in the history
Featured image: add height and width attributes on the front depending on setting.
Co-authored-by: Aaron Robertshaw <60436221+aaronrobertshaw@users.noreply.github.com>
  • Loading branch information
carolinan committed Jan 13, 2023
1 parent a35b3f2 commit e0f919c
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions packages/block-library/src/post-featured-image/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,27 @@ function render_block_core_post_featured_image( $attributes, $content, $block )
if ( $is_link ) {
$link_target = $attributes['linkTarget'];
$rel = ! empty( $attributes['rel'] ) ? 'rel="' . esc_attr( $attributes['rel'] ) . '"' : '';
$height = ! empty( $attributes['height'] ) ? 'style="' . esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . '"' : '';
$featured_image = sprintf(
'<a href="%1$s" target="%2$s" %3$s>%4$s%5$s</a>',
'<a href="%1$s" target="%2$s" %3$s %4$s>%5$s%6$s</a>',
get_the_permalink( $post_ID ),
esc_attr( $link_target ),
$rel,
$height,
$featured_image,
$overlay_markup
);
} else {
$featured_image = $featured_image . $overlay_markup;
}

$wrapper_attributes = empty( $attributes['width'] )
? get_block_wrapper_attributes()
: get_block_wrapper_attributes( array( 'style' => "width:{$attributes['width']};" ) );

$width = ! empty( $attributes['width'] ) ? esc_attr( safecss_filter_attr( 'width:' . $attributes['width'] ) ) . ';' : '';
$height = ! empty( $attributes['height'] ) ? esc_attr( safecss_filter_attr( 'height:' . $attributes['height'] ) ) . ';' : '';
if ( ! $height && ! $width ) {
$wrapper_attributes = get_block_wrapper_attributes();
} else {
$wrapper_attributes = get_block_wrapper_attributes( array( 'style' => $width . $height ) );
}
return "<figure {$wrapper_attributes}>{$featured_image}</figure>";
}

Expand Down

0 comments on commit e0f919c

Please sign in to comment.