Last active
January 16, 2025 08:49
-
-
Save wy4tt34rp/97249004e947c0b199043c88256ac082 to your computer and use it in GitHub Desktop.
WooCommerce Filter Adding Captions to Gallery Thumbnails
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/*** Add to Child Theme functions.php to show media caption under product thumbnails in the WooCommerce Product Gallery. ***/ | |
add_filter('woocommerce_single_product_image_thumbnail_html', function($html, $attachment_id) { | |
$caption = get_post_field('post_excerpt', $attachment_id); | |
if(trim($caption)) { | |
$html = str_replace('</div>', '<span class="gtnCaps">' . $caption . '</span></div>', $html); | |
} | |
return $html; | |
}, 10, 2); |
Hi, for me this repeats the caption of the product image, and not displays the thumbnail's caption. Can you please help me with this? Thank you
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there a way to display on main product only not gallery thumbnails?