Site icon Hip-Hop Website Design and Development

get_the_post_thumbnail() title and alt attributes not displaying

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
  1. echo get_the_post_thumbnail($post->ID, ‘post-thumbnail’, [‘class’ => ‘classTest’] ); //works

  2. echo get_the_post_thumbnail($post->ID, ‘post-thumbnail’, [‘alt’ => ‘altTest’] ); //doesn’t work

  3. echo get_the_post_thumbnail($post->ID, ‘post-thumbnail’, [‘title’ => ‘titleTest’] ); //doesn’t work


  1. <img width="940" height="150" src="https:/...imgsrc.jpg" class="classTest attachment-post-thumbnail size-post-thumbnail wp-post-image"> classTest added

  2. <img width="940" height="150" src="https:/...imgsrc.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image"> altTest missing

  3. <img width="940" height="150" src="https:/...imgsrc.jpg" class="attachment-post-thumbnail size-post-thumbnail wp-post-image"> titleTest missing