Commit dc942ec677b for woocommerce
commit dc942ec677b79d3c9889f681859ed1be52b9ddcd
Author: SH Sajal Chowdhury <72102985+shsajalchowdhury@users.noreply.github.com>
Date: Tue May 5 13:52:25 2026 +0600
Fix missing height attribute on category images when uncropped (#64345)
* Fix missing height attribute on category images when uncropped
When thumbnail cropping is set to 'Uncropped', wc_get_image_size()
returns an empty height value, resulting in HTML like height=""
on category image elements. This causes CLS issues and PageSpeed
warnings about missing explicit width and height attributes.
The fix uses the actual image dimensions returned by
wp_get_attachment_image_src() (which provides width at index [1]
and height at index [2]) when the configured height is empty.
Fixes #38153
* Harden uncropped check with explicit crop and height validation per reviewer feedback
* Add changefile(s) from automation for the following project(s): woocommerce
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/64345-fix-38153-clean-category-image-height b/plugins/woocommerce/changelog/64345-fix-38153-clean-category-image-height
new file mode 100644
index 00000000000..d82d028a8e8
--- /dev/null
+++ b/plugins/woocommerce/changelog/64345-fix-38153-clean-category-image-height
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+Comment: Fix the missing height attribute on category images when uncropped
+
diff --git a/plugins/woocommerce/includes/wc-template-functions.php b/plugins/woocommerce/includes/wc-template-functions.php
index 4b20e650060..b6fd148c144 100644
--- a/plugins/woocommerce/includes/wc-template-functions.php
+++ b/plugins/woocommerce/includes/wc-template-functions.php
@@ -3013,6 +3013,12 @@ if ( ! function_exists( 'woocommerce_subcategory_thumbnail' ) ) {
$image = $image_data[0];
$image_srcset = function_exists( 'wp_get_attachment_image_srcset' ) ? wp_get_attachment_image_srcset( $thumbnail_id, $small_thumbnail_size ) : false;
$image_sizes = function_exists( 'wp_get_attachment_image_sizes' ) ? wp_get_attachment_image_sizes( $thumbnail_id, $small_thumbnail_size ) : false;
+
+ $uncropped = 0 === ( $dimensions['crop'] ?? 0 ) && '' === ( $dimensions['height'] ?? '' );
+ if ( $uncropped && isset( $image_data[1], $image_data[2] ) ) {
+ $dimensions['width'] = $image_data[1];
+ $dimensions['height'] = $image_data[2];
+ }
} else {
$image = wc_placeholder_img_src();
$image_srcset = false;