diff --git a/src/class-tiny-source-base.php b/src/class-tiny-source-base.php
index 859b208..c6f3cff 100644
--- a/src/class-tiny-source-base.php
+++ b/src/class-tiny-source-base.php
@@ -240,6 +240,11 @@ protected function create_alternative_sources( $original_source_html ) {
$source_attr_parts[ $attr ] = $attr_value;
}
}
+ } else {
+ $sizes_value = $this->get_attribute_value( $original_source_html, 'sizes' );
+ if ( $sizes_value ) {
+ $source_attr_parts['sizes'] = $sizes_value;
+ }
}
$source_attr_parts['type'] = $mimetype;
diff --git a/test/unit/TinyPictureTest.php b/test/unit/TinyPictureTest.php
index 68ba295..95298d2 100644
--- a/test/unit/TinyPictureTest.php
+++ b/test/unit/TinyPictureTest.php
@@ -366,6 +366,21 @@ public function test_image_without_src() {
$this->assertSame($expected, $output);
}
+ /**
+ * sizes attribute on
also have to be set to elements
+ */
+ public function test_img_sizes_attribute_is_propagated_to_sources() {
+ $this->wp->createImage(1000, '2026/04', 'test-320w.webp');
+ $this->wp->createImage(1000, '2026/04', 'test-640w.webp');
+ $this->wp->createImage(1000, '2026/04', 'test.webp');
+
+ $input = '
';
+ $expected = '
';
+ $output = $this->tiny_picture->replace_sources($input);
+
+ $this->assertSame($expected, $output);
+ }
+
/**
* Images with only a srcset are valid and will be wrapped
*/