Site logo

Archived topic

Caption Text overlapping

3 replies · Started by Henry on November 28, 2022

Viewing posts 1–4 of 4

Longer Texts on image caption overlaps on mobile view. Below is the code used for image caption.

Here's Sample link. Kindly view on mobile : https://scholarsly.com/how-old-is-ranboo-net-worth-real-name-how-tall-face/

add_filter( 'post_thumbnail_html', 'custom_add_post_thumbnail_caption',10,5 );
 
function custom_add_post_thumbnail_caption($html, $post_id, $post_thumbnail_id, $size, $attr) {
 
if( $html == '' || ! is_single() || ! is_main_query() ) {
  
    return $html;
  
} else {
  
    $out = '';
  
    $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
  
    if ($thumbnail_image && isset($thumbnail_image[0])) {
  
        $image = wp_get_attachment_image_src($post_thumbnail_id, $size);
 
        if($thumbnail_image[0]->post_excerpt) 
            $out .= '<div class="wp-caption thumb-caption">';
  
        $out .= $html;
  
        if($thumbnail_image[0]->post_excerpt) 
            $out .= '<p class="wp-caption-text thumb-caption-text">'.$thumbnail_image[0]->post_excerpt.'</p></div>';
   
    }
 
    return $out;
   
}
}

Thanks Leo,

Problem solved.

No problem :)

This archived topic is closed to new replies.