Okay
  Public Ticket #2887413
Image Caption
Closed

Comments

  •  8
    Elena started the conversation

    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

  • [deleted] replied

    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:

    <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):

    span.image-caption {
        position: absolute;
        display: block;
        bottom: 20px;
        left: 20px;
        background: black;
        color: #fff;
        padding: 5px;
    }

    And the result:

    medium
    (view large image)

    medium
    (view large image)



  •  8
    Elena replied

    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

  • [deleted] replied

    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:

    <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>

    My apologies.

  •  8
    Elena replied

    Thank you Arlind.

    Now it works.


    lg Elena