WordPress - 图片标题存在 - Gutenberg 不会自动获取它

问题描述 投票:0回答:1

在问这个问题之前,我从上午 10:00 到晚上 20:00 支付了 9 个小时 :( 我尝试了一切......但没有运气。

好吧,我已经设置了图像的信息:alt text, title, caption, description

古腾堡编辑器可以获取 Alt 文本、图像标题,但在高级 -> 标题属性选项卡中缺少“标题”。

如何让 Gutenberge 从图像 post_id 中获取标题而无需再次手动重写? 谢谢...

php wordpress wordpress-gutenberg
1个回答
0
投票

我测试了在WordPress 6.2中添加带有title设置的图片,确认默认不添加title属性

在查看源代码时,我发现

title
键不包含在
imageProps
pickRelevantMediaFiles 中 - 尽管它是 image 块中的块属性
title
被常用。似乎与 Post featured image: Add title attribute #46880 GitHub 上的 PR(目前在撰写本文时被阻止)有关。

一个潜在的解决方案可能是扩展图像块的编辑()功能以包括

title
例如:

export const pickRelevantMediaFiles = ( image, size ) => {
    const imageProps = Object.fromEntries(
        Object.entries( image ?? {} ).filter( ( [ key ] ) =>
            [ 'alt', 'id', 'link', 'caption', 'title' ].includes( key ) 
            // Added 'title' to prevent value being "undefined"
        )
    );
...
}
© www.soinside.com 2019 - 2024. All rights reserved.