I am using a code to call WP thumbnails and want to add a title="" tag. I would like the title to call the_title... how do I do so? I want to assign the title tribute to the image, not the link.

My code:

<?php if ( has_post_thumbnail() ) { the_post_thumbnail( 'thmb-archive' ); } ?>

Use the arguments available for the_post_thumbnail() function as written in the codex.

Edit: just did a test with this and it worked for me:

$post_title = the_title( '', '', false);//get the title
$attr = array('title' => $post_title);//set the parameter 
the_post_thumbnail('full', $attr);//call the function
| improve this answer | |
  • Tried it, but I'm trying to assign the title attribute to the image, not the link. – AndrettiMilas Aug 2 '11 at 21:19
  • Edited my answer, give a look and let me know. – kevin Aug 2 '11 at 21:29
  • I don't believe this works correctly, when done correctly it should assign the title to the image. – AndrettiMilas Aug 2 '11 at 21:35
  • Yes, to the thumbnail actually, i just tested on a project i'm on with this exact function. – kevin Aug 2 '11 at 21:42
  • themeforward.com/demo2/templates/archive When no image is assigned a title is in place of the image. However, the code above does not do the same. – AndrettiMilas Aug 2 '11 at 21:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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