Woocommerce Gallery Image Caption: Use “caption” — not “alt tag”. Keep alt tag as is
Phew! Here is the code for functions.php. add_filter( ‘woocommerce_single_product_image_thumbnail_html’, ‘change_alt_to_caption_gallery_images’, 10, 2 ); function change_alt_to_caption_gallery_images ( $wc_get_gallery_image_html, $image_id ){ $caption = get_post_field( ‘post_excerpt’, $image_id ); if ( !empty($caption) && !empty($wc_get_gallery_image_html) ) { $caption = str_replace( ‘”‘, “””, $caption ); $caption_repl=”data-caption=”” . $caption . ‘”‘; $wc_get_gallery_image_html = preg_replace( ‘/data-thumb-alt=”[^”]+”/’, $caption_repl, $wc_get_gallery_image_html ); } return $wc_get_gallery_image_html; }