Black Friday sale! Get up to 25% off GP Premium! Learn more ➝

[Resolved] Featured Image Caption NOT showing

Home Forums Support [Resolved] Featured Image Caption NOT showing

Home Forums Support Featured Image Caption NOT showing

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1373179
    Alejandro

    Hi,
    I want to see the featured image caption.
    To achieve that I set up a Hook as you describe in this post

    I set it after_entry_header but it shows just after_entry_title.
    I tried to switch where the code hooks (tried after_entry_title as well) to check if there is any function swapping but it stills show after_entry_title….

    Any help please?

    #1373270
    David
    Staff
    Customer Support
    #1373687
    Alejandro

    Thanks David, it works pretty fine.
    I am only interested in showing it in the single post, not on the blog roll or elsewhere. I am using WP Show Posts PRO and I don’t want to show the caption through it.
    What should I change then?

    Thanks!

    #1373705
    David
    Staff
    Customer Support

    try this code instead:

    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() ) {
            // Get Excerpt of thumbnail
            $thumbnail_image = get_posts(array('p' => $post_thumbnail_id, 'post_type' => 'attachment'));
            $thumbnail_caption = $thumbnail_image[0]->post_excerpt;
    
            if ( $thumbnail_caption ) {
                $html .= '<div class="wp-caption thumb-caption">
                <p class="wp-caption-text thumb-caption-text">'. $thumbnail_caption .'</p>
                </div>';
            }
        }
        return $html;
    }
    #1373710
    Alejandro

    You made it!

    Works flawlessly. Thanks for the help.

    #1373718
    David
    Staff
    Customer Support

    Awesome – glad to be of help

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