Site logo

[Resolved] Show ‘Description’ instead of ‘Caption’ for Featured Image

Home Forums Support [Resolved] Show ‘Description’ instead of ‘Caption’ for Featured Image

Home Forums Support Show ‘Description’ instead of ‘Caption’ for Featured Image

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #2464051
    Yolanda

    Hello great support 🙂

    Is it possible to show the Description of an image below the featured image, instead of the Caption?

    I’ve added the PHP code as mentioned in a previous topic, and it’s working well. But I’d like to show the text which is in de Description of the images.

    Thank you!
    Yolanda, NL

    https://www.yory.nl/

    #2464077
    David
    Staff
    Customer Support

    Hi there,

    which PHP did you use to add the caption ? As we should be able to change that to display the description instead.

    #2464082
    Yolanda

    Hello David!

    This is the code I’ve pasted. I’m anxious to change the word Caption into Description, as I don’t want to break my site.

    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;

    }
    }

    #2464110
    David
    Staff
    Customer Support

    In this line:

    if($thumbnail_image[0]->post_excerpt)

    replace: post_excerpt with post_content

    #2464115
    Yolanda

    Oh no, that broke down a part of my site!

    https://i.postimg.cc/1tWR6KwP/20221216-000138.jpg

    Any other suggestions?

    #2464125
    David
    Staff
    Customer Support
    #2464191
    Yolanda

    Thank you again, that worked!!

    #2464200
    David
    Staff
    Customer Support

    Glad to hear that!

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