[Support request] Display caption on featured image

Home Forums Support [Support request] Display caption on featured image

Home Forums Support Display caption on featured image

Viewing 15 posts - 1 through 15 (of 16 total)
  • Author
    Posts
  • #1056786
    Capital Link

    How can I display the caption of featured image from the default wp posts?

    I install the https://wordpress.org/plugins/featured-image-caption/ and I can see the caption text that I add on that fields of this plugin.

    #1056797
    David
    Staff
    Customer Support

    Hi there,

    is this to be displayed on the Single Post or the Blog / Archives?

    #1056824
    Capital Link

    Yes, if I have on the functions.php the

    add_action( 'generate_before_content', 'generate_post_image_caption' );
    function generate_post_image_caption()
    {
    		
    	// If there's no featured image, return
    	if ( ! has_post_thumbnail() )
    		return;
    		
    	//Modified. This is checking for a post that IS a single post and NOT a 404
    	if ( is_singular() && ! is_404()) {
    	?>
    	<?php if ( function_exists( 'cc_featured_image_caption' ) ) : ?>
    <?php cc_featured_image_caption(); ?><?php endif; ?>
    		
    	<?php
    	}
    }

    from https://generatepress.com/forums/topic/caption-for-post-thumbnails/page/2/

    P.S. The captions is displayed on top of featured images instead of bottom.

    #1057245
    David
    Staff
    Customer Support

    Hi there,

    instead of using the plugin and that filter you can use the Code i provide here:

    https://generatepress.com/forums/topic/cant-display-featured-image-captions/#post-854633

    Will need to see the site once its in place to help with any styling.

    #1059142
    Capital Link

    Where do I have to paste the provided php code?

    In functions.php?

    If so I paste it and nothing happened 🙁

    #1059208
    David
    Staff
    Customer Support

    Yes – it goes in functions.php or the code snippets plugin.
    Can you leave the code in place and link me to the site so i can take a look?

    #1059219
    Capital Link

    Ok I add that code.

    How can i give you access?
    The site is not public.

    Can you give me your e-mail?

    #1059231
    David
    Staff
    Customer Support

    You can see URL and login details via the Accounts Issue form:

    https://generatepress.com/contact/

    Please add the URL for this topic to the form so we can track

    #1059245
    Capital Link

    Added!

    It was also nice to have ticket number when we send issues – credentials etc.

    #1059304
    David
    Staff
    Customer Support

    Did you resize the image in the Customizer > Layout > Blog ?
    If so can you clear the sizes – just delete the numbers and hit apply.

    #1059322
    Capital Link

    The caption text displayed at the home page but not in the post.

    Do I have to change anything else?

    I use child theme.

    #1059337
    David
    Staff
    Customer Support

    In the Customizer > Layout > Blog under Featured images you can change the size for Posts, Pages and Archives, can you make sure the Post is set to Auto by removing any sizes in there.

    #1059355
    Capital Link

    I see now the caption but only if the size of the image is set to Auto.

    If I set 500 px I cannot see the caption. Why?

    #1059376
    David
    Staff
    Customer Support

    Resizing the image changes the function used to display the image.
    Try this snippet instead:

    add_filter( 'generate_single_featured_image_html', 'custom_add_post_thumbnail_caption',25,1 );
    function custom_add_post_thumbnail_caption($image_html) {
        $get_caption = get_post(get_post_thumbnail_id())->post_excerpt;
        if( $image_html == '' && empty($get_caption)) { 
            return $image_html;
        } else {
            $caption = '<div class="wp-caption thumb-caption">' . $image_html . '<p class="wp-caption-text thumb-caption-text">' . $get_caption .'</p></div>';
        }
        return $caption;
    }
    #1871823
    vanbawilian

    Thank you

    This is working very nice now.

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