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); |
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
Thank you :)