Last active
October 26, 2021 14:43
-
-
Save wy4tt34rp/97249004e947c0b199043c88256ac082 to your computer and use it in GitHub Desktop.
WooCommerce Filter Adding Captions to Gallery Thumbnails
This file contains 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); |
It works for me too, using Woocommerce in combination with WPML in 2021. Translations are correct. Thanks a lot.
Thanks for the code! How can I edit the font size for this?
Thanks for the code! How can I edit the font size for this?
@fifionana3 - Just ID the CSS class via Web Inspector and change as needed. Sorry, I don't remember what it is off the top of my head. It might be "gtnCaps".
Thank you :)
Is there a way to display on main product only not gallery thumbnails?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Thanks much, this is great.