How do I add post title as alt tag in a post? I tried using array(title => '.the_title.')
but it didnt work. I think I am not suppose to use the_title
. I tired using get_the_title
as well.
Thanks
3 Answers
@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>");