- This topic has 15 replies, 2 voices, and was last updated 2 years, 9 months ago by David.
-
AuthorPosts
-
November 8, 2019 at 5:10 am #1056786Capital 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.
November 8, 2019 at 5:30 am #1056797DavidStaffCustomer SupportHi there,
is this to be displayed on the Single Post or the Blog / Archives?
November 8, 2019 at 6:03 am #1056824Capital LinkYes, 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.
November 8, 2019 at 11:03 am #1057245DavidStaffCustomer SupportHi 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.
November 11, 2019 at 12:59 am #1059142Capital LinkWhere do I have to paste the provided php code?
In functions.php?
If so I paste it and nothing happened 🙁
November 11, 2019 at 2:30 am #1059208DavidStaffCustomer SupportYes – 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?November 11, 2019 at 2:42 am #1059219Capital LinkOk I add that code.
How can i give you access?
The site is not public.Can you give me your e-mail?
November 11, 2019 at 2:57 am #1059231DavidStaffCustomer SupportYou 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
November 11, 2019 at 3:17 am #1059245Capital LinkAdded!
It was also nice to have ticket number when we send issues – credentials etc.
November 11, 2019 at 4:57 am #1059304DavidStaffCustomer SupportDid you resize the image in the Customizer > Layout > Blog ?
If so can you clear the sizes – just delete the numbers and hit apply.November 11, 2019 at 5:11 am #1059322Capital LinkThe caption text displayed at the home page but not in the post.
Do I have to change anything else?
I use child theme.
November 11, 2019 at 5:25 am #1059337DavidStaffCustomer SupportIn 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.
November 11, 2019 at 5:47 am #1059355Capital LinkI 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?
November 11, 2019 at 6:20 am #1059376DavidStaffCustomer SupportResizing 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; }
July 26, 2021 at 10:17 am #1871823vanbawilianThank you
This is working very nice now.
-
AuthorPosts
- You must be logged in to reply to this topic.