[Resolved] Can't display featured image captions

Home Forums Support Can't display featured image captions

  • This topic has 10 replies, 3 voices, and was last updated 4 months ago by David.
Viewing 11 posts - 1 through 11 (of 11 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?

    GeneratePress 2.2.2
    GP Premium 1.7.8
    #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
    #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
Viewing 11 posts - 1 through 11 (of 11 total)
  • You must be logged in to reply to this topic.