在Wordpress中以编程方式添加带有ALT文本的特色图像?

在Wordpress中以编程方式添加带有ALT文本的特色图像?,wordpress,image,text,alt,featured,Wordpress,Image,Text,Alt,Featured,有一些例子说明了如何在wordpress中以编程方式添加带有特色图像的帖子,但我也需要添加带有特色图像和ALT文本的帖子。我怎么能做那样的事 谢谢。如果查看wp\u get\u attachment\u image函数的源代码,您可以看到alt文本是如何提取的: 'alt' => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) )) 从那里很容易找到如何更新alt文本的方

有一些例子说明了如何在wordpress中以编程方式添加带有特色图像的帖子,但我也需要添加带有特色图像和ALT文本的帖子。我怎么能做那样的事


谢谢。

如果查看wp\u get\u attachment\u image函数的源代码,您可以看到alt文本是如何提取的:

'alt'   => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ))
从那里很容易找到如何更新alt文本的方法

update_post_meta($attachment_id, '_wp_attachment_image_alt', 'My Alt Text');

如果查看wp_get_attachment_image函数的源代码,可以看到alt文本是如何提取的:

'alt'   => trim(strip_tags( get_post_meta($attachment_id, '_wp_attachment_image_alt', true) ))
从那里很容易找到如何更新alt文本的方法

update_post_meta($attachment_id, '_wp_attachment_image_alt', 'My Alt Text');