[Resolved] Can't display featured image captions

Home Forums Support [Resolved] Can't display featured image captions

Home Forums Support Can't display featured image captions

Viewing 15 posts - 1 through 15 (of 33 total)
  • Author
    Posts
  • #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?

    #854633
    David
    Staff
    Customer Support

    Hi 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.

    #854652
    Johan

    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?

    #854661
    Johan

    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.

    #854767
    David
    Staff
    Customer Support

    You can give it some custom styling like so:

    .featured-image .wp-caption-text {
        padding: 10px;
        max-width: 770px;
        margin: auto;
        line-height: 1.4em;
    }
    #855027
    Johan

    Thanks. It now works.

    #855184
    David
    Staff
    Customer Support

    Glad to be of help

    #1178521
    Daniel

    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, Daniel

    #1178531
    David
    Staff
    Customer Support

    Hi 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

    #1178749
    Daniel

    David, you’re today my personal hero. That works! Thanks a lot!

    #1178753
    David
    Staff
    Customer Support

    You’re welcome ๐Ÿ™‚

    #1404979
    David

    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.

    example

    Hope you can help me with that and I promise this is my last question for a while ๐Ÿ˜‰

    Thank you!

    #1405141
    David
    Staff
    Customer Support

    Hi 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.

    #1433077
    Yolanda

    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, Yolanda

    #1433098
    Leo
    Staff
    Customer Support

    Did you clear the caching plugin after adding the code?

Viewing 15 posts - 1 through 15 (of 33 total)
  • You must be logged in to reply to this topic.