- This topic has 9 replies, 3 voices, and was last updated 2 years, 11 months ago by David.
-
AuthorPosts
-
April 29, 2021 at 6:15 am #1755394JC
To display credits I need to show image caption below the image on post pages.
If you can help point me in the right direction and possibly that I can do it via elements. The 2 solutions on the forum does not include how to via elements and also the one that did work added it after the post title and not the image so I must have used the wrong hook for it.
Thank you in advance ๐
April 29, 2021 at 7:27 am #1755776DavidStaffCustomer SupportHi there,
you would need to create a shortcode to display the caption, which can then be added using Elements – heres an example which also includes a fallback text if there is no image caption set:
April 29, 2021 at 11:30 am #1756193JCHi David,
Thank you for the quick response.
Ok, so if I do a shortcode might as well add it to the functions.php only so how do I get it to display after the featured image (below it) by adding it to the functions.php?
April 29, 2021 at 6:07 pm #1756567ElvinStaffCustomer SupportHi there,
You can use this filter to modify the featured image to add your caption.
https://docs.generatepress.com/article/generate_featured_image_output/You can either insert a
do_shortcode()
in it containing your created shortcode or code something within the filter.April 29, 2021 at 11:38 pm #1756892JCHi Elvin,
It’s safe to assume that I am not proficient when it comes to PHP but of all the solutions this one ended up working for me;
https://generatepress.com/forums/topic/featured-image-badge/
April 29, 2021 at 11:40 pm #1756898ElvinStaffCustomer SupportHave you sorted this out? The link you’ve added points to a search results list.
Let us know if you need further help. ๐
April 29, 2021 at 11:50 pm #1756914JCI’ve updated the link to the correct one, https://generatepress.com/forums/topic/featured-image-badge/
The only problem is that displays the description and not the caption so how do I modify the below to display the caption and not the description from the image?
add_action( 'post_thumbnail_html', 'db_auto_single_featured_description', 10 ); function db_auto_single_featured_description( $html ) { $get_description = get_post(get_post_thumbnail_id())->post_excerpt; if ( is_single() && !empty($get_description) ){ $html .= '<div class="wp-caption">'. $get_description . '</div>'; } return $html; }
April 30, 2021 at 1:32 am #1757071DavidStaffCustomer SupportUsing this snippet for the Caption:
add_action( 'post_thumbnail_html', 'db_auto_single_featured_caption', 10 ); function db_auto_single_featured_caption( $html ) { $caption = get_the_post_thumbnail_caption(); if ( is_single() && !empty($caption) ){ $html .= '<div class="wp-caption">'. $caption . '</div>'; } return $html; }
And a little bit off CSS to style it:
.featured-image .wp-caption { line-height: 1.5em; font-size: 12px; text-align: left; }
April 30, 2021 at 6:36 am #1757458JCThank you David! You are a superstar as always!
April 30, 2021 at 4:46 pm #1758384DavidStaffCustomer SupportGlad to be of help
-
AuthorPosts
- You must be logged in to reply to this topic.