我将 WordPress 与 Listingpro 模板一起使用,我一直在寻找解决方案并找到了以下内容:
// An attachment/image ID is all that's needed to retrieve its alt and title attributes.
$image_id = get_post_thumbnail_id();
$image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE);
$image_title = get_the_title($image_id);
但是,当我添加这个 alt='$image_alt'
时,显示了一个空的 alt。
最佳答案
<img src="whatever-src" alt="'.$image_alt.'">
当它在 echo 中时,这就是您所需要的。 仅当有与该图像相关联的任何 alt 时。
关于php - 空 alt 标签 wordpress,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59473891/