1

I want to add a title to my featured image, how I can add this item:

$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='$p->permalink'>". // null for current $post->ID (use within loop)
    get_the_post_thumbnail( null, 'post-thumbnail', $attr ).
    "</a>");

my site is : https://abzarwp.com

1
  • 3
    what do you want as title?...the image name or post name?? Commented Sep 27, 2017 at 6:41

1 Answer 1

0

I'm not sure about your question, but the below code is more correct.

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

echo sprintf( '<a href="%s">%s</a>', get_the_permalink(), get_the_post_thumbnail( null, 'post-thumbnail', $attr ) );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.