Archived topic
How to show Featured Image Caption
18 replies · Started by Sagar on October 27, 2020
Hi,
I want to show featured image caption on all my blog posts. Captions are to be entered manually to give the attribution.
Like this news website has given
https://www.hindustantimes.com/it-s-viral/dad-s-complete-guide-to-baby-video-is-absolutely-hilarious-watch/story-opDXsEccg885ZFQXLnWooL.html
The caption is: “The image shows a shot from the video. (Instagram/@howtodadnz)”
Remember that, it will be different for all the blog posts.
Thank you
Hi there,
This snippet is the best for this:
https://gist.github.com/diggeddy/5f7c3a4584a8beb51febc9c4f33d6c5c
It needs to be added using one of these methods:
Adding PHP: https://docs.generatepress.com/article/adding-php/
Then you can just use the default Caption field from WordPress media library:
https://www.screencast.com/t/asrNiTgXp8WB
Let me know if this helps :)
Thank you, Leo.
But when I'm checking my AMP pages, the caption is showing two times. What's wrong now?
Check here: https://urbanhomecart.com/best-dishwasher-india/amp/
the caption is 'Dishwasher'
I'm really sure how AMP handles a WordPress option mod like this unfortunately.
Would this CSS help?
.wp-caption .wp-caption-text:not(.thumb-caption-text) {
display: none;
}
Adding CSS: https://docs.generatepress.com/article/adding-css/
Hi Leo,
Why don't you enable this as a default option for all the users? If anyone wants to use it they will use otherwise no.
It's just a small thing which much be enabled by default.
Which Amp plugin are you using ?
I'm using AMP by Automattic
https://wordpress.org/plugins/amp/
In the code Leo provided a link to here:
Try changing this:
} else {
to
} elseif( !is_amp_endpoint() ) {
Why don’t you enable this as a default option for all the users? If anyone wants to use it they will use otherwise no.
It’s just a small thing that must be enabled by default.
Playing with codes is a scary thing for me for my website.
} else {
to
} elseif( !is_amp_endpoint() ) {
I did this. Now the featured image is not showing in the amp pages.
I'll check with David to see if the code can be modified some more.
Thanks for the suggestion.
I'll mention it to our team :)
Sorry about that - revert that change and instead try updating this line:
if( $html == '' ) {
to
if( $html == '' || is_amp_endpoint() ) {
Again, none of the featured images showing on any AMP page after this code.
Sorry, I cleared the cache. Now it is working well. But please take my feedback to enable this featured image caption by default in the GP theme.
As I'm really too far away from coding.