[Support request] Looking for caption field name

Home Forums Support Looking for caption field name

Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #1274447
    Lisa

    HI,
    I want to be able to give a photo credit to the Featured Image on my news site on the Single Post’s Page Hero with the other post metadata. What is the caption’s field name?

    I can see the fields for the post meta. Is there a comparable field name for the image’s caption? That’s where I’ve been storing the photo credits.

    The caption shows appropriately when the photo is added in-line. But I can’t quite find the field name. I feel like if I had that field name I could just add it to the Page Hero fields like the post meta.

    {{post_author}} | {{post_date}} | {{post_terms.category}} | {{img.caption}}

    I even loaded up the Advanced Custom Field plugin, which is very nice and I was able to create a new field in my Media Library, but I couldn’t get that Custom Field the show in my page hero. 🙁

    Thanks for any guidance. (I keep thinking I’m rocking this and then come up with new ideas that are always beyond my skills.)

    #1274584
    Tom
    Lead Developer
    Lead Developer

    Hi Lisa,

    I assume adding the custom field to the actual post/page the image is displaying on wouldn’t work? That would be the easiest route..

    Otherwise, we’d probably need to write a custom shortcode to get the featured image ID. How are you adding the featured image? As a background?

    #1274600
    Lisa

    Hi,
    Right, I created the custom field which showed in the media upload UI properly, I added content to that, and then tried to place that field name in the Page Hero like the {{post_date}} and {{post_author}}. It made space for it on the frontend but didn’t show that content. So obviously the Hero is working, I just called the wrong field. Looks like I need to call the shortcode rather than the field name. And I’m not sure how to make that shortcode/template tag.

    I add the Featured Image when I’m writing the Post, and it comes in as background image. I haven’t changed any of the defaults on the Dispatch Single Post element.

    Thanks for the guidance.

    #1275001
    David
    Staff
    Customer Support

    Hi there,

    See this topic for the PHP snippet required to create a Shortcode to display the featured image caption:

    https://generatepress.com/forums/topic/generatepress-dispatch-questions/#post-1093846

    #1283262
    Lisa

    Hi,
    I was able to put this in and with the help of Code Snippets, I only had a *small* heart attack worrying about adding PHP. I appreciate your help.

    One last detail: the resulting caption in the Hero (Single Post) is coming up on the line below. I wonder if there is something I could modify so all the meta fields come up on the same line?
    Sample page: https://elkonewsonline.com/city-of-elko-phase-1-limited-reopening/

    If not, I will take what I have.
    Thanks,
    -L.

    #1283764
    David
    Staff
    Customer Support

    Could you share the rest of the HTML you have in the Hero ?

    #1284596
    Lisa

    I think it’s pretty close to the default:

    `<h1>
    {{post_title}}
    </h1>
    <p>
    {{post_author}} | {{post_date}} | {{post_terms.category}} | [featured_caption]
    </p>’

    I might try to assign classes and modify in the CSS, but it looks great. The only small issue is that the caption where I’m storing my image credit info, is showing on a separate line.

    Thanks,
    -L.

    #1285037
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try changing the code David linked to to this:

    add_shortcode( 'featured_caption', 'db_featured_image_caption' );
    function db_featured_image_caption() {
        global $post;
        if ( has_post_thumbnail( $post->ID )) {
            ob_start();
            $get_description = get_post(get_post_thumbnail_id())->post_excerpt;
            if(!empty($get_description)) {    
                $content = '<span class="featured-caption">' . $get_description . '</span>';
                ob_end_clean();
                return $content;
            }
        }
    }

    Let me know 🙂

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