I am attempting to display ‘alt’ and ‘title’ attributes on a post thumbnail image, but the only attribute that actually displays as passed is ‘class’. ‘alt’ and ‘title’ are missing. Any ideas what could be the cause?
$thumbnail_id = get_post_thumbnail_id( );
$image_alt = get_post_meta($thumbnail_id, '_wp_attachment_image_alt', true);
echo $image_alt; //correct alt attribute text
-
echo get_the_post_thumbnail($post->ID, ‘post-thumbnail’, [‘class’ => ‘classTest’] ); //works
-
echo get_the_post_thumbnail($post->ID, ‘post-thumbnail’, [‘alt’ => ‘altTest’] ); //doesn’t work
-
echo get_the_post_thumbnail($post->ID, ‘post-thumbnail’, [‘title’ => ‘titleTest’] ); //doesn’t work
-
<img width="940" height="150" src="https:/...imgsrc.jpg" class="classTest attachment-post-thumbnail size-post-thumbnail wp-post-image">
classTest added -
<img width="940" height="150" src="https:/...imgsrc.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image">
altTest missing -
<img width="940" height="150" src="https:/...imgsrc.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image">
titleTest missing