Add post title as alt tag for featured image

@its_me got it almost right. Those args must be 2nd resp. 3rd Parameter, not first:

$attr = array(
    'title' => 'howdy partner',
    'alt'   => 'a nice view of the ocean',
);

// pick one, note 2 or 3 arguments:
the_post_thumbnail( 'post-thumbnail', $attr );

echo("<a href="https://wordpress.stackexchange.com/questions/57968/$p->permalink">". // null for current $post->ID (use within loop)
    get_the_post_thumbnail( null, 'post-thumbnail', $attr ).
    "</a>");

Leave a Comment