Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #1211555

    The following code, when clicked, opens an image with lightbox:

    $html .= '<a href="' . esc_url(get_the_post_thumbnail_url($v, 'full')) . '">';
    $html .= '<img src="' . esc_url(get_the_post_thumbnail_url($v, 'thumbnail')) . '" alt="' . esc_html(get_the_title($v)) . '" />';
    $html .= '</a>';

    The above code does not have a caption under the image. How do I add esc_html(get_the_title($v)) as the caption?

    • This topic was modified 4 years, 7 months ago by GCSkye.
    #1212688

    Any ideas on this?

    #1213175

    Hi,

    Sorry for the delay. You can insert the title or caption like so:

    $html .= '<span class="wp-caption">'.esc_html(get_the_title($v)).'</span>';
    

    Place the code right below this line:

    $html .= '<img src="' . esc_url(get_the_post_thumbnail_url($v, 'thumbnail')) . '" alt="' . esc_html(get_the_title($v)) . '" />';
    

    Best regards,
    Ismael

    #1214126

    Hi Ismael,

    Thank you so much for the response! This put the text below the image before clicking it. See top image link below. I’m trying to get it so after the image is clicked, the lightbox will have a caption. See second image. Red circle should display text.

    #1215808

    Hi,

    Sorry for the late reply!

    Please update your code and update “alt” to “title”:

    $html .= '<a href="' . esc_url(get_the_post_thumbnail_url($v, 'full')) . '">';
    $html .= '<img src="' . esc_url(get_the_post_thumbnail_url($v, 'thumbnail')) . '" title="' . esc_html(get_the_title($v)) . '" />';
    $html .= '</a>';

    Best regards,
    Yigit

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.