【发布时间】:2016-06-01 16:29:29
【问题描述】:
我正在尝试在网站上显示图像时为图像添加 alt 属性,但到目前为止还没有成功。
非常感谢,这是我正在尝试的代码:
<?php $featured = wp_get_attachment_image_src(get_post_thumbnail_id($post->ID), '1440_1712'); ?>
<?php $alt = get_post_meta($post->ID, '_wp_attachment_image_alt', true); ?>
<div class='img-half-wrap' style='background-image: url("<?php echo $featured[0]; ?>");' alt='<?php echo $alt; ?>'>
我尝试将 $post->ID 更改为 $featured,但没有成功。 非常感谢任何帮助。
谢谢
【问题讨论】:
-
如果您在没有可选参数的情况下测试
get_post_meta($post->ID),您会看到什么结果? -
感谢您的及时回复。我看到了 alt="Array"。