[Support request] Featured Image Caption

Home Forums Support [Support request] Featured Image Caption

Home Forums Support Featured Image Caption

Viewing 15 posts - 1 through 15 (of 18 total)
  • Author
    Posts
  • #598522
    Christine

    Hello,

    I am unable to view featured image captions. I would like to add captions to my images within posts (not to be seen on the preview menu), is there a way I can do this?

    Thanks!

    #598608
    David
    Staff
    Customer Support

    Hi Christine,

    you can add this snippet:

    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>';
        }
    }

    https://docs.generatepress.com/article/adding-php/

    #598622
    Christine

    Hey,

    I think I’m confused. I’m trying to add a visible caption underneath photos in posts, and am able to type one into the featured image photo editor (there is a box for it). Where does that caption go, if not under the photo?

    I added the code you gave but nothing changed.

    Thank you!

    #598623
    Christine

    OK – I see the caption if I add the image into the post… but then there are two of the same photos back to back.

    #598627
    David
    Staff
    Customer Support

    Hi Christine, i think i may be confused to.
    So Captions are added to the Images in the Media library.
    If you add a featured image to a post with a caption then the caption will be displayed below that on the post.
    Is this what you needed?

    #598629
    Christine

    Yes, I added the caption in the Media Library. Unfortunately, I don’t think it appears when the image is used as a “Featured Image.”

    #598630
    David
    Staff
    Customer Support

    Did you add the code i provided above? And if so is it sill in place?

    #598631
    Christine

    Hi David,

    I added it into the Simple CSS plugin and didn’t see the caption.

    #598640
    David
    Staff
    Customer Support

    Aah ok. the code is a PHP Snippet. The way to add the code is mentioned here:

    https://docs.generatepress.com/article/adding-php/

    I would advise using the Code Snippets plugin mentioned. Install plugin, paste the code into a New snippet and Save and Activate

    #1168514
    tbgr

    Hello.

    I installed the Code Snippets plugin and entered/activated the code mentioned above:

    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>’;
    }
    }

    The caption DID appear but it’s not UNDER the photo; rather it’s ABOVE the title of the blog post.

    (I’m using the Marketer premium theme.)

    Any suggestions? Thank you!

    #1168528
    Leo
    Staff
    Customer Support

    Any chance you can open a new topic and link us to the page in question?

    Thanks ๐Ÿ™‚

    #1168542
    tbgr

    Hi, Leo.

    The website is under construction and isn’t live yet. Is there a way I can email you an image of the problem?

    #1168561
    Leo
    Staff
    Customer Support

    Can you open a new topic and use this site to upload an image first?
    https://postimages.org/

    Thanks ๐Ÿ™‚

    #1168568
    tbgr

    Yes. Will do in a moment.

    Thank you.

    #1168571
    tbgr

    Just uploaded the jpg.

    Not sure if you received it.

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