Skip to content

Commit 454c669

Browse files
Additional check for
1 parent f784475 commit 454c669

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

plugins/auto-sizes/includes/improve-calculate-sizes.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,11 @@ function auto_sizes_calculate_better_sizes( int $id, $size, string $align, int $
200200

201201
case 'wide':
202202
$layout_width = auto_sizes_get_layout_width( 'wide' );
203-
if ( str_ends_with( $layout_width, 'px' ) ) {
203+
if (
204+
str_ends_with( $layout_width, 'px' ) &&
205+
( $container_relative_width > 0.0 ||
206+
$container_relative_width < 1.0 )
207+
) {
204208
// First remove 'px' from width.
205209
$layout_width = str_replace( 'px', '', $layout_width );
206210
// Convert to float for better precision.
@@ -220,7 +224,11 @@ function auto_sizes_calculate_better_sizes( int $id, $size, string $align, int $
220224
* If the layout width is in pixels, we can compare against the image width
221225
* on the server. Otherwise, we need to rely on CSS functions.
222226
*/
223-
if ( str_ends_with( $layout_width, 'px' ) ) {
227+
if (
228+
str_ends_with( $layout_width, 'px' ) &&
229+
( $container_relative_width > 0.0 ||
230+
$container_relative_width < 1.0 )
231+
) {
224232
// First remove 'px' from width.
225233
$layout_width = str_replace( 'px', '', $layout_width );
226234
// Convert to float for better precision.
@@ -337,7 +345,10 @@ function auto_sizes_filter_render_block_context( array $context, array $block, ?
337345
}
338346

339347
// Multiply with parent's width if available.
340-
if ( isset( $parent_block->context['container_relative_width'] ) ) {
348+
if (
349+
isset( $parent_block->context['container_relative_width'] ) &&
350+
( $current_width > 0.0 || $current_width < 1.0 )
351+
) {
341352
$context['container_relative_width'] = $parent_block->context['container_relative_width'] * $current_width;
342353
} else {
343354
$context['container_relative_width'] = $current_width;

0 commit comments

Comments
 (0)