0

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' ); } ?>

1 Answer 1

2

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
11
  • Tried it, but I'm trying to assign the title attribute to the image, not the link. Commented Aug 2, 2011 at 21:19
  • Edited my answer, give a look and let me know. Commented Aug 2, 2011 at 21:29
  • I don't believe this works correctly, when done correctly it should assign the title to the image. Commented Aug 2, 2011 at 21:35
  • Yes, to the thumbnail actually, i just tested on a project i'm on with this exact function. Commented Aug 2, 2011 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. Commented Aug 2, 2011 at 21:52

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.