Site logo

[Support request] How to add caption in featured image

Home Forums Support [Support request] How to add caption in featured image

Home Forums Support How to add caption in featured image

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #2504585
    Vivek

    Hi
    I want to add caption in the featured image
    i tried looking to other topics and used this code

    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 == ” ) {

    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 .= ‘

    ‘;

    $out .= $html;

    if($thumbnail_image[0]->post_excerpt)
    $out .= ‘<p class=”wp-caption-text thumb-caption-text”>’.$thumbnail_image[0]->post_excerpt.'</p>

    ‘;

    }

    return $out;

    }
    }

    but still the caption is not in a perfect position

    Here is the link of the screenshot:
    https://ibb.co/dbpcrrx
    https://ibb.co/jb2ySd4

    Please reply to my other queries

    #2504953
    David
    Staff
    Customer Support

    Hi there,

    can you share a link to the site?
    You can use the Private Information field to share URLs and login details

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