- This topic has 32 replies, 8 voices, and was last updated 2 years, 4 months ago by
Fernando.
-
AuthorPosts
-
March 30, 2019 at 2:52 pm #854588
Johan
Hello.
I want image captions for featured images in posts to show, so I can give attribution and copyright. But no matter what I do, it does not seem to be possible.With Simple CSS I try to ad this:
.post-image-above-header .inside-article .featured-image {
margin-bottom: 0 !important;
}
.featured_caption {
font-size: 75%;
padding-top: 5px;
opacity: .8;
margin-bottom: 1.5em;
}`I also try to add some different solutions from these here forums. Like this:
add_action( ‘generate_after_entry_header’, ‘db_featured_image_caption’, 15 );
function db_featured_image_caption() {
$get_description = get_post(get_post_thumbnail_id())->post_excerpt;
if(!empty($get_description)){
echo ‘<span class=”featured_caption”>’ . $get_description . ‘</span>’;
}
}`But with no luck.
I also try to add things like this:
.featured_caption { text-align; center; }
Still no luck.
Not even with this:
.page-header-image-single { text-align: center; } .featured_caption { text-align; center; }
Furthermore I try to add some PHP snippets:
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>'; } }
No luck with that either.
What can I do to get captions under the featured images in my posts?
March 30, 2019 at 3:58 pm #854633David
StaffCustomer SupportHi there,
try this PHP Snippet:
https://gist.github.com/diggeddy/5f7c3a4584a8beb51febc9c4f33d6c5c
It only applies to featured images within posts, not when used a background for a Header Element.
March 30, 2019 at 4:54 pm #854652Johan
Thanks. It kinda works, but the letters of the caption floats up into the pictures. Is there any way to adjust the caption text a little down, and to the left, so that it looks just like the normal captions that show up under any other images in a post?
March 30, 2019 at 5:07 pm #854661Johan
Furthermore it would be preferable to have more than one line of text for the caption under the featured image in posts. In case the attributions are longer than one line.
March 31, 2019 at 1:43 am #854767David
StaffCustomer SupportYou can give it some custom styling like so:
.featured-image .wp-caption-text { padding: 10px; max-width: 770px; margin: auto; line-height: 1.4em; }
March 31, 2019 at 6:58 am #855027Johan
Thanks. It now works.
March 31, 2019 at 12:01 pm #855184David
StaffCustomer SupportGlad to be of help
February 27, 2020 at 5:38 am #1178521Daniel
Hello David,
just used this snippet for a while and it works fine. I wonder if there’s a way to add this filter only on a single post?
Best, DanielFebruary 27, 2020 at 5:44 am #1178531David
StaffCustomer SupportHi there,
you can try swapping this line:
if( $html == '' ) {
for
if( $html == '' || ! is_single() ) {
So it returns the default HTML if there is no featured image or is !NOT a single post
February 27, 2020 at 7:05 am #1178749Daniel
David, you’re today my personal hero. That works! Thanks a lot!
February 27, 2020 at 7:08 am #1178753David
StaffCustomer SupportYou’re welcome 🙂
August 16, 2020 at 7:38 am #1404979David
Hello David! Thanks for the information it helped me a lot.
We are using Shortcode Ultimate (Unfortunately) to feature some other posts within the article. It shots the title, an exerpt and the image. So now I see the caption not only for the image on the original post itself but also on other pages when the featured images is used.
Hope you can help me with that and I promise this is my last question for a while 😉
Thank you!
August 16, 2020 at 8:12 am #1405141David
StaffCustomer SupportHi there,
would you mind raising a new topic where you can share a link so i can take a look. The most i reckon will be some CSS to hide it.
September 6, 2020 at 10:21 am #1433077Yolanda
Hi David,
I also would like to show the caption text below a featured image on a post.
I’ve added your php code as a snippet, and added the css code to the customizer.
but I don’t see the text back on the front end.An example is https://yolandalooptdoor.yory.nl/mijn-interview-in-het-blad-radar/
Can you help out?
Thank you,
Bye, YolandaSeptember 6, 2020 at 11:03 am #1433098Leo
StaffCustomer SupportDid you clear the caching plugin after adding the code?
-
AuthorPosts
- You must be logged in to reply to this topic.