Archived topic
Caption for featured image (post only)
11 replies · Started by Bruce on May 28, 2021
Hello! I would like to have an option to display a caption for featured images in posts. Not all of my featured images need to display a caption, but some definitely do (primarily for attribution).
I've looked through the theme settings and do not see an option to turn this on. Is it there and I am missing it?
And if not, is there code I can add somewhere to either turn it on for all, OR to add a meta box to the post editor screen to turn it on per post?
Thanks for your help!
Hi Bruce,
This is an option we will be adding in the future version.
For now you can try this PHP snippet:
https://gist.github.com/diggeddy/5f7c3a4584a8beb51febc9c4f33d6c5c
This would add captions to all featured images though.
OK, glad to know it is coming.
Where would I add that snippet? I found it earlier, but wasn't sure where to add it. Thanks!
Hi Bruce,
This is how you add PHP :)
https://docs.generatepress.com/article/adding-php/
Ah, it's a standalone function. I thought perhaps it had to go into the loop somewhere.
I already have a custom functions plugin that I built. I'll add it to that and see what happens. Thanks!
No problem :)
An update:
I added the function to my custom functions plug-in, and it seemed to work fine. But, I didn't like the styling, so I added some custom CSS and that looked good to me.
Then, I had one caption that took two lines, but wasn't doing the "carriage return" to the second line -- instead, it was overwriting the first line. Used Inspect to learn that it was inheriting line.height=0 from the image CSS. I added a line-height property to the CSS, and all seemed well.
Then today, I had two stories where the overwriting happened in the body of the story. Each graf was all on one line. Inspect said that the body content was inheriting the line height from the image CSS.
I wound up having to turn off the caption function, take out the CSS, remove the caption, and finally flush the cache to get things cleared up. So now, no captions for featured images.
Not sure why the line-height setting from the image was rolling down the page to the body content.
So, any chance that new version with the optional captions is coming soon? :-)
Can you link me to the page in question so I can see the issue?
Interesting -- I set up a staging copy of the site, so I wouldn't break the production site, and proceeded to turn everything back on. I expected the problem to show up immediately, but it did not. I kept fiddling with it, trying to replicate it, but could not.
So, I went back to the production site and turned everything on there as well, including the custom CSS, and all seems to be working correctly. Weird.
Thanks for your offer of help. I'll let you know if the problem returns.
No problem :)
Hi Leo,
any idea, when the mentioned option will be in the customizer or backend? Just to know, when the custom function need to be removed. The code itself work like a charm and just need some space with css.
Thank you!
Hi there,
no definitive timeline on that yet.
If you're a block editor user then you will be able to do this within a block element and GenerateBlocks 1.5 very soon