You need to define $image_alt
and $image_title
. I don’t see where you did it in your code.
You need to change/add like this
<?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 } ?>
Image’s ‘alt’ text is stored as a string in wp_postmeta with the meta_key of ‘_wp_attachment_image_alt’.
That you can grab like this
$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 } ?>