• Resolved Gemini23

    (@gemini23)


    Hi,, I need to be able to display credit to the photographer on the featured images – how can I display a caption?

    I see that there is/was a plugin to display it but this hasn’t been updated for the last 3 Worpdress updates.

    • This topic was modified 11 months ago by Gemini23.
Viewing 3 replies - 1 through 3 (of 3 total)
  • Hi @gemini23,

    You can try adding the following snippet to your site

    function display_featured_image_caption() {
        global $post;
    
        if (has_post_thumbnail($post->ID)) {
            $thumbnail_id = get_post_thumbnail_id($post->ID);
    
            $caption = get_post($thumbnail_id)->post_excerpt;
    
            if (!empty($caption)) {
                echo '<div class="featured-image-caption">' . esc_html($caption) . '</div>';
            }
        }
    }
    
    add_action('astra_blog_single_featured_image_after', 'display_featured_image_caption');

    It looks like this on my dev site.

    You can style it further with custom CSS.

    I hope it will help.

    Kind regards,
    Herman ??

    Thread Starter Gemini23

    (@gemini23)

    Many thanks, Herman. ??

    No problem, @gemini23! So happy can be a help.

    Feel free to start a new thread if there’s anything else related to Astra, we can help you with.

    Kind regards,
    Herman ??

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to display caption on featured image?’ is closed to new replies.