admin管理员组

文章数量:1134247

What happens:

  • Write a post
  • Create a gallery
  • Upload a random picture
  • Set caption to "test"
  • Publish Post
  • Go to Media -> Select the picture from before
  • Set caption to "changed" and save
  • Go back to post
  • Check the image
  • Image caption still shows "test" -> Should be "changed"

So if I ever update the media library with proper captions, alt text and titles it looks like they will never be updated on older posts. Is this how it should work?

If this is not a bug, but a feature, how to fix this? Where are these block-information on the post saved?

Kind Regards, Ben

What happens:

  • Write a post
  • Create a gallery
  • Upload a random picture
  • Set caption to "test"
  • Publish Post
  • Go to Media -> Select the picture from before
  • Set caption to "changed" and save
  • Go back to post
  • Check the image
  • Image caption still shows "test" -> Should be "changed"

So if I ever update the media library with proper captions, alt text and titles it looks like they will never be updated on older posts. Is this how it should work?

If this is not a bug, but a feature, how to fix this? Where are these block-information on the post saved?

Kind Regards, Ben

Share Improve this question edited Mar 1, 2022 at 17:12 CasualBen asked Mar 1, 2022 at 17:04 CasualBenCasualBen 1336 bronze badges 3
  • I created a bug report for WordPress to fix this issue core.trac.wordpress.org/ticket/61613 – Michael Altfield Commented Jul 9, 2024 at 20:04
  • See also therenegadecoder.com/meta/… – Michael Altfield Commented Jul 9, 2024 at 21:35
  • See also this plugin (with a feature propagate media attribute changes) github.com/arunbasillal/… – Michael Altfield Commented Jul 10, 2024 at 1:20
Add a comment  | 

2 Answers 2

Reset to default 1

Yes, that is Core behavior. The Post Editor saves whatever alt text, caption, and title you use while editing a specific Post/Page/CPT into its post content, in HTML if you are using the Classic Editor, or in Image block attributes if you are using the Block Editor.

One workaround is to always upload media directly to the Media Library. While you upload, set your desired alt text, captions, and titles. After you're done there, edit the Posts/Pages/CPTs where you want to add the images. Since the info is stored in the Media Library, when you add the image to a post's content, that will prepopulate from what you already entered.

If you need to go back and change existing image info in posts, it is probably easiest to follow a similar pattern: set the alt text, captions, and titles in the Media Library first. Then, you'll have to search through your Posts/Pages/CPTs, but you can remove the images there and re-add them, and they'll have the info prepopulated.

I've found a solution to this and created a plugin for the current WordPress Version: https://github.com/DasBen/CasualBen-Automatic-Alt-And-Caption-Text/tree/1.1.0

Everytime an image is rendered, there will now be a query to update alt-text and captions.

For those of you who would rather write their own. Here is the code:

add_filter( 'render_block', function( $content, $block ) {
if( 'core/image' !== $block['blockName'] )
    return $content;

    $alt = get_post_meta( $block['attrs']['id'], '_wp_attachment_image_alt', true );
    if( empty( $alt ) ) return $content;

    // Empty alt
    if( false !== strpos( $content, 'alt=""' ) ) {
        $content = str_replace( 'alt=""', 'alt="' . $alt . '"', $content );

    // No alt
    } elseif( false === strpos( $content, 'alt="' ) ) {
        $content = str_replace( 'src="', 'alt="' . $alt . '" src="', $content );
    }

    return $content;
}, 10, 2 );

本文标签: galleryMedia changes not updating posts