Skip to content

[Post Featured Image]: add option to display image caption/credit #40946

Open

Description

@samiff

What problem does this address?

When using a block theme that leverages wp:post-featured-image to display a post's featured image, there is no caption being rendered by that block, nor is there an option to do so.

Jetpack for example offers external media providers like Openverse and Pexels that users can select from when setting a featured image. Generally, the Caption field is used to credit the source, and you'll see that themes like Twenty Twenty will render the caption/credit for featured images by default.

Concern originally raised in: Automattic/jetpack#23408

What is your proposed solution?

Given the fluid discussion in: #27617

I'm not quite sure at this point, but I think it'd be nice to have an option that would show the caption/credit for the featured image - especially when the images are sourced from a third-party. At bare minimum, at least have the figcaption output in the HTML even if it's not visually displayed.

Activity

  1. kaffeeringe commented on Nov 25, 2022

    @kaffeeringe

    I can't use Gutenberg themes, until it displays the description caption. I stored all the copyright notices there.

  2. hagege commented on Dec 31, 2022

    @hagege

    That would indeed be a nice option, e.g. by ticking in the properties whether that should be shown.

  3. carolinan commented on Jan 2, 2023

    @carolinan
    Contributor

    @kaffeeringe even in classic PHP based themes, displaying the description is a custom solution.
    Chances are that this field will never be supported by the block by default. You may want to consider moving the data to another field in your database, like the caption.

  4. carolinan commented on Jan 4, 2023

    @carolinan
    Contributor

    I learnt that none of the media captions use the caption text from the media library.
    So if we want the caption to use the media library data by default, they all need to be updated, not only the post featured image block.

    I want to read up on the history and why this choice was made.
    It is probably because the same media can be used in multiple places and one caption may not be enough because it is situational. But it has that side effect that existing data is not easily available.

  5. self-assigned this
    on Jan 4, 2023
  6. kaffeeringe commented on Jan 4, 2023

    @kaffeeringe

    @carolinan Sorry, I mixed up the fields. I use Wordpress in German and there caption and description are called "Beschriftung" and "Beschreibung" and I always mix them up. I use the caption field with my images.

    It would be nice if the caption was only the suggested caption if you use an image in a block or as featured image. So you can reuse an image with different captions.

  7. carolinan commented on Jan 4, 2023

    @carolinan
    Contributor

    It could be used as a pre-filled placeholder, interesting idea.

  8. greening commented on Jun 19, 2023

    @greening

    I'm refactoring a couple of websites into FSE, and I really wish this was available in the Featured Image block. (I don't need it for copyright declarations, but sure would like it for traditional captions.

  9. jethin commented on Aug 17, 2023

    @jethin

    Greetings,

    I agree that the ability to show captions on featured images should be rolled into WP. Until then, I came up with the following workaround:

    Set up a block variation. "For now, let’s create variations.js and put the file in our theme’s assets/js folder":

    wp.blocks.registerBlockVariation(
        'core/post-featured-image',
        {
            name: 'sotp_post_featured_image',
            title: 'Post Featured Image + Caption',
            description: 'Displays the post\'s featured image with caption.',
            isActive: [ 'namespace' ],
            attributes: {
                namespace: 'sotp_post_featured_image',
                className: 'sotp-post-featured-image'
            },
            scope: [ 'inserter' ]
        }
    );

    "Next, you need to enqueue variations.js... This code should generally be placed in your theme’s functions.php..."

    function example_enqueue_block_variations() {
    	wp_enqueue_script(
    		'example-enqueue-block-variations',
    		get_template_directory_uri() . '/assets/js/variations.js',
    		array( 'wp-blocks', 'wp-dom-ready' ),
    		wp_get_theme()->get( 'Version' ),
    		false
    	);
    }
    add_action( 'enqueue_block_editor_assets', 'example_enqueue_block_variations' );

    And finally filter the block render (functions.php):

    function include_feature_image_caption($block_content, $block){
        if ( isset($block['attrs']['className']) && $block['attrs']['className'] === 'sotp-post-featured-image') {
            $caption = '<figcaption class="wp-element-caption">' . get_the_post_thumbnail_caption() . '</figcaption>';
            $block_content = str_replace('</figure>', $caption . '</figure>', $block_content);
        }
        return $block_content;
    }
    add_filter( 'render_block_core/post-featured-image', 'include_feature_image_caption', 10, 2 );

    I make no guarantees for this code. Hope it helps someone.

    [updated enqueuing as per @janvitos comment below.]

  10. janvitos commented on Aug 21, 2023

    @janvitos

    Hope it helps someone

    Works like a charm, thanks @jethin!

    Just one thing: How do you register your block variation? Using PHP?

    I did it this way, but I'm not sure it's the "proper way":

    add_action( 'enqueue_block_editor_assets', function() {
        wp_enqueue_script( 'prefix-block-variations', THEME_JS_URL . 'block-variations.js', array( 'wp-blocks' ) );
    });
    
  11. kevinpoot commented on Sep 21, 2023

    @kevinpoot

    IMO this should definitely be included inside the block with an option to disable (or enable) it. Any update on this being implemented anytime soon?

  12. supernovia commented on Oct 25, 2023

    @supernovia

    Wondering about this since another user asked about it today. I'd love to see the ability to put credits / captions on featured images, especially with Openverse. :)

  13. removed their assignment
    on Nov 27, 2023
  14. nickbohle commented on Jan 4, 2024

    @nickbohle

    Hi all,

    I just had the issue myself that I wanted to display the caption below a featured post image. (Using TT4, caption is saved with the image in the media library). Unfortunately, this was not possible.

    As mentioned above, I would love the caption option to be added to the "Post Featured image" block like in the "Image" block. But different to the "image" block, I would prefer that the display of the caption is opt-in and not opt-out. This way, users are not confused, when suddenly captions appear under their featured post images.

  15. iamtakashi commented on Apr 9, 2024

    @iamtakashi

    +1 !!

  16. nickbohle commented on Apr 11, 2024

    @nickbohle

    Actually, it could be the easiest way to promote the OpenVerse, if the caption plus the licence would include a direct link to the openverse. Right, Matt?

  17. dhanson-wp commented on Apr 12, 2024

    @dhanson-wp

    +1 !!!!! to the featured image caption, and an alt text field in the block settings.

  18. noellesteegs commented on Apr 17, 2024

    @noellesteegs

    Thank you @jethin for the workaround. I think this feature would make a great addition.

  19. jordonrupp-dev commented on Aug 12, 2024

    @jordonrupp-dev

    +1

  20. westonruter commented on May 18, 2025

    @westonruter
    Member

    I've made plugin to implement this in the Featured Image block by adding an "Add caption" button to the block toolbar, the same button that appears in the Image block. When selected, a placeholder caption is displayed in the Site Editor and the current caption is rendered in a figcaption on the frontend like @jethin does in #40946 (comment). Writeup: Adding Caption & Lightbox to the Featured Image Block.

  21. JiveDig commented on Jun 25, 2025

    @JiveDig

    @westonruter Thanks for the plugin, it works great.

    This should definitely be in core, but I'm glad we have that quick plugin option for now.

  22. nathan-barlow commented on Aug 4, 2026

    @nathan-barlow

    We also would find this useful. Our post template displays the post featured image, and it's critical for us that there is an accessible way to add a caption beneath it for image attribution and/or other caption context. Thanks @westonruter for the workaround--it would be great if this could be added to core.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions