[Resolved] Can't display featured image captions

Home Forums Support [Resolved] Can't display featured image captions

Home Forums Support Can't display featured image captions

Viewing 15 posts - 16 through 30 (of 33 total)
  • Author
    Posts
  • #1433610
    Yolanda

    Yes, thank you, that was stupid of me… ๐Ÿ˜‰

    #1433829
    Leo
    Staff
    Customer Support

    No problem ๐Ÿ™‚

    #2269763
    guyhanchet

    I’ve been looking for this for some time and finally took the plunge on adding a snippet of code using the recommended plugin and a bit of CSS as suggested here. It all works as I hoped.

    #2270081
    David
    Staff
    Customer Support

    Glad to hear you found that of use!

    #2368284
    Erik

    This has mostly worked for me, with one problem: The caption is also showing up underneath thumbnail images for the posts in the sidebar. Is there a way to prevent this, so that it only shows up on the main featured image at the top of the post?

    #2368378
    Fernando
    Customer Support

    Hi Erik,

    Try replacing this:

    if( $html == '' ) {

    with:

    if( $html == '' || ! is_single() || ! is_main_query() ) {

    #2437992
    Henry

    Removing caption in single page sidebar didn’t work for me after replacing with

    if( $html == ” || ! is_single() || ! is_main_query() ) {

    #2438024
    Henry

    Also, the code here, https://gist.github.com/diggeddy/5f7c3a4584a8beb51febc9c4f33d6c5c kind of floats the featured image to the left. I don’t want text around the featured image.

    UPDATE: RESOLVED! Forgot I added CSS.

    #2438070
    Fernando
    Customer Support

    I see. Glad you resolved the issue!

    #2438302
    Henry

    THIS PROBLEM has not been resolved

    #2438314
    Fernando
    Customer Support

    I see. Can you make sure that the quotation marks you used in the code are not slanted? To make sure, can you add the code you added here? Make sure to Highlight the code, and click on “CODE” here in the forum text box so it’s added as a code.

    #2438333
    Henry

    To recall, Everything works fine except for the single-post sidebar. See https://scholarsly.com/uniqlo-student-discount/

    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;
       
    }
    }
    #2438353
    Henry

    Also you’ll notice the the sidebar “Latest Post” push to the right and not left. How do I resolve that?

    #2438380
    Fernando
    Customer Support

    I see. I can see the captions from my end. See: https://share.getcloudapp.com/geuOlqqR

    Also, with regards to your second inquiry, can you clarify a bit more about how you would like it to look?

    Alternatively, you can also use a GB Query Loop Block to show the Latest Posts. GB Image Blocks has the option to add captions as well.

    Example: https://share.getcloudapp.com/KounDwl9
    Also see: https://share.getcloudapp.com/4gu4bJOl

    Reference: https://docs.generateblocks.com/article/query-loop-overview/

    #2438423
    Henry

    I actually don’t want the caption shown.

    Well, I’ve updated the side using GB Query Loop Block (Check the link above). How do I achieve something similar to https://share.getcloudapp.com/P8uNpyro.

    And another with numbering & without featured image.

Viewing 15 posts - 16 through 30 (of 33 total)
  • You must be logged in to reply to this topic.