-
AuthorPosts
-
May 9, 2024 at 2:54 pm #1442812
Hi, I tried this code but I didn’t work. https://kriesi.at/support/topic/adding-captions-underneath-featured-images-on-posts/
May 9, 2024 at 7:38 pm #1442837Hey williamslyd,
Can you explain more about what you would like to achieve, a caption under the featured image, or over the image like a overlay? Perhaps a mockup would help.Best regards,
MikeMay 9, 2024 at 7:42 pm #1442838Hi, I’d like a caption under the featured image, like in this image: https://monicadesigns.ca/display-caption-to-featured-image-on-extra-theme-post-page/
Thanks!May 11, 2024 at 3:47 pm #1442968Hi,
Thank you for your patience, please try following these steps, first add a caption to your featured image in the media library:
Then add this css to your child theme stylesheet or the theme option Quick CSS:.single-post .single-big a:after { content: attr(title); }
and the caption should show like this:
Best regards,
MikeMay 11, 2024 at 4:13 pm #1442979This reply has been marked as private.May 11, 2024 at 7:41 pm #1442998Hi,
Thanks for the feedback, remove the css above and keep the caption in your featured image in the media library, and then try adding this code to the end of your child theme functions.php file in Appearance ▸ Editor:function custom_post_featured_image_link( $image_link ) { if(is_single() && has_post_thumbnail()) { $image_link = get_the_post_thumbnail(); $thumbnail_id = get_post_thumbnail_id(); $thumbnail_caption = wp_get_attachment_caption($thumbnail_id); $caption_div = '<div class="featured-image-caption" style="text-align: center;">' . esc_html($thumbnail_caption) . '</div>'; $image_link = $image_link . $caption_div; } return $image_link; } add_filter( 'avf_post_featured_image_link', 'custom_post_featured_image_link', 10, 3 );
the caption should show like this:
I’m not sure how it will show for your different layouts as the WordPress login above didn’t work for me so I couldn’t test, so give it a try.Best regards,
MikeMay 16, 2024 at 1:12 am #1443782Hi there, that is definately better, but the caption is still not the same width of the image – it is running across the entire width of the page, even if I am using my template that calls for the featured image to be 1000 px max width. See link in private content. Thanks!
May 16, 2024 at 1:15 am #1443784This reply has been marked as private.May 16, 2024 at 11:34 am #1443869Hi,
The code above adds a class to the featured image caption called featured-image-caption it looks like you have found this and tried some css to set the max-width, but you have an error with a letter where a number should be: max-width: 1e3px;
I changed it to 900px for you:
I see that you tried to add some custom body classes to use some different css:
but I don’t see this on the frontend and I’m not sure how you are doing this, but this is a good approach.Best regards,
Mike -
AuthorPosts
- You must be logged in to reply to this topic.