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
2 Answers
Reset to default 1Yes, 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
版权声明:本文标题:gallery - Media changes not updating posts 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736826883a1954529.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论