I have a question about the product images on the product page in Woo.
I would like the function of pointing the mouse over the image that the Image Caption is already displayed. Not only in the Lightbox gallery. Is that possible without a lot of effort?
Actually there is no built-in way to do this but I can give you a code snippet to show image captions in product images, so here is what you need to do:
1. Add the following code in Theme Options > Other Settings > Custom JavaScript > Footer JavaScript:
<script>
jQuery( document ).ready( function( $ ) {
$( '.main-product-images .woocommerce-product-gallery__image' ).each( function( i, el ) {
var $img = $( el ).find( 'a img[title]' ).first();
if ( $img.length && img.attr( 'title' ).length ) {
$img.closest( 'a' ).append( '<span class="image-caption">' + $img.attr( 'title' ) + '</span>' );
}
} );
} );
</script>
2. Add CSS to style the caption and move it around the product picture (modify the CSS to your own styling preferences):
Hello,
I have a question about the product images on the product page in Woo.
I would like the function of pointing the mouse over the image that the Image Caption is already displayed. Not only in the Lightbox gallery. Is that possible without a lot of effort?
Thanks.
lg Elena
Hi Elena,
Actually there is no built-in way to do this but I can give you a code snippet to show image captions in product images, so here is what you need to do:
1. Add the following code in Theme Options > Other Settings > Custom JavaScript > Footer JavaScript:
2. Add CSS to style the caption and move it around the product picture (modify the CSS to your own styling preferences):
And the result:
(view large image)
(view large image)
Hi Arlind,
first of all, thank you very much for your answer.
I followed your instructions. Unfortunately, the image caption is not displayed for me.
lg Elena
Hi Elena,
I am sorry about this but there was a small typo problem in the code snippet I have sent you, please replace with this one and it should work:
My apologies.
Thank you Arlind.
Now it works.
lg Elena