您需要定义$image_alt
和$image_title
. 我看不出你在代码中做了什么。
您需要这样更改/添加
<?php if ( has_post_thumbnail() ) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),’thumbnail’ );
$attachment_meta = get_post(get_post_thumbnail_id());
echo \'<img width="100%" src="\'.$image_src[0].\'" alt="\'.$attachment_meta->post_excerpt.\'" title="\'.$attachment_meta->post_title.\'">\';
} else { ?>
<img src="<?php bloginfo(\'template_directory\'); ?>/img/fallback.jpg" class="img-responsive" />
<?php } ?>
图像的“alt”文本以字符串形式存储在wp\\u postmeta中,meta\\u键为“\\u wp\\u attachment\\u Image\\u alt”。
你可以这样抓
$img_alt = get_post_meta($thumb_id, \'_wp_attachment_image_alt\', true);
EDIT:
<?php if ( has_post_thumbnail() ) {
$image_src = wp_get_attachment_image_src( get_post_thumbnail_id(),\'thumbnail\' );
$attachment_meta = get_post(get_post_thumbnail_id());
$img_alt = get_post_meta(get_post_thumbnail_id(), \'_wp_attachment_image_alt\', true);
echo \'<img width="100%" src="\'.$image_src[0].\'" alt="\'.$img_alt.\'" title="\'.$attachment_meta->post_title.\'">\';
} else { ?>
<img src="<?php bloginfo(\'template_directory\'); ?>/img/fallback.jpg" class="img-responsive" />
<?php } ?>