Skip to content

Commit

Permalink
Cover: Add missing min-height style when using fixed background with …
Browse files Browse the repository at this point in the history
…a featured image (#41693)

* Fixed issue of background min height
* Updated code according to feedback
* Fixed code sniffer issues
  • Loading branch information
akasunil authored Jun 17, 2022
1 parent 943aaef commit 51e09fa
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions packages/block-library/src/cover/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,19 @@ function render_block_core_cover( $attributes, $content ) {
update_post_thumbnail_cache();
}
$current_featured_image = get_the_post_thumbnail_url();
$content = preg_replace(

$styles = 'background-image:url(' . esc_url( $current_featured_image ) . '); ';

if ( isset( $attributes['minHeight'] ) ) {
$height_unit = empty( $attributes['minHeightUnit'] ) ? 'px' : $attributes['minHeightUnit'];
$height = " min-height:{$attributes['minHeight']}{$height_unit}";

$styles .= $height;
}

$content = preg_replace(
'/class=\".*?\"/',
'${0} style="background-image:url(' . esc_url( $current_featured_image ) . ')"',
'${0} style="' . $styles . '"',
$content,
1
);
Expand Down

0 comments on commit 51e09fa

Please sign in to comment.