Archived topic
Featured Image Caption
17 replies · Started by Christine on June 12, 2018
Hello,
I am unable to view featured image captions. I would like to add captions to my images within posts (not to be seen on the preview menu), is there a way I can do this?
Thanks!
Hi Christine,
you can add this snippet:
add_action( 'generate_before_content', 'db_featured_image_caption', 15 );
function db_featured_image_caption() {
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
if(!empty($get_description) && is_single() ){
echo '<span class="featured_caption">' . $get_description . '</span>';
}
}
Hey,
I think I'm confused. I'm trying to add a visible caption underneath photos in posts, and am able to type one into the featured image photo editor (there is a box for it). Where does that caption go, if not under the photo?
I added the code you gave but nothing changed.
Thank you!
OK - I see the caption if I add the image into the post... but then there are two of the same photos back to back.
Hi Christine, i think i may be confused to.
So Captions are added to the Images in the Media library.
If you add a featured image to a post with a caption then the caption will be displayed below that on the post.
Is this what you needed?
Yes, I added the caption in the Media Library. Unfortunately, I don't think it appears when the image is used as a "Featured Image."
Did you add the code i provided above? And if so is it sill in place?
Hi David,
I added it into the Simple CSS plugin and didn't see the caption.
Aah ok. the code is a PHP Snippet. The way to add the code is mentioned here:
https://docs.generatepress.com/article/adding-php/
I would advise using the Code Snippets plugin mentioned. Install plugin, paste the code into a New snippet and Save and Activate
Hello.
I installed the Code Snippets plugin and entered/activated the code mentioned above:
add_action( 'generate_before_content', 'db_featured_image_caption', 15 );
function db_featured_image_caption() {
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
if(!empty($get_description) && is_single() ){
echo '<span class="featured_caption">' . $get_description . '</span>';
}
}
The caption DID appear but it's not UNDER the photo; rather it's ABOVE the title of the blog post.
(I'm using the Marketer premium theme.)
Any suggestions? Thank you!
Any chance you can open a new topic and link us to the page in question?
Thanks :)
Hi, Leo.
The website is under construction and isn't live yet. Is there a way I can email you an image of the problem?
Can you open a new topic and use this site to upload an image first?
https://postimages.org/
Thanks :)
Yes. Will do in a moment.
Thank you.
Just uploaded the jpg.
Not sure if you received it.