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?
Any ideas on this?
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
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.
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