Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.
 <?php 
 if ( has_post_thumbnail()) {
   $large_image_url = wp_get_attachment_image_src( get_post_thumbnail_id(), 'large');
   echo '<a href="' . $large_image_url[0] . '" >';
   the_post_thumbnail('medium');
   echo '</a>';
 }
 ?>

This code adds a big image to the thumbnail image. What can I do add title to 'large' image?

share|improve this question
    
I add this code title="' . the_title_attribute('echo=0') . '" but it is add title page, i need title thumbnail image. –  Евгений Березовский May 28 '13 at 19:47
    
What 'title' are you trying to add? The image's title? –  Pat J May 28 '13 at 20:26
    
Yes it is, Pat, i try add title of image... –  Евгений Березовский May 30 '13 at 6:23

2 Answers 2

Check the Codex. the_post_thumbnail accepts two parameters, the second of which is $attr-- "attributes".

the_post_thumbnail('full',array('title'=>'yay! a title!'));

The Codex entry for the_post_thumbnail is not clear on what is and is not allowed as an "attribute" but it appears to depend on wp_get_attachment_image and by filters applied by that function. title does work though. I checked.

share|improve this answer

Not sure if you mean title attribute or title as in caption. The code below would echo the image title as a caption.

EDIT - up-voted @s_ha_dum's answer as it looks like you were looking for the title attribute.

EDIT - `wp_get_attachment_image_src' returns an array with the image URL in the first position.

<?php 
if ( has_post_thumbnail()) {
   $your_thumb_id = get_post_thumbnail_id();
   $args = array(
     'post_type' => 'attachment',
     'numberposts' => 1,
     'post_status' => null,
     'p' => $your_thumb_id
   );

   $attachments = get_posts( $args );
   if ( $attachments ) {
      foreach ( $attachments as $attachment ) {
         $large_src = wp_get_attachment_image_src( $attachment->ID, 'large' );
         echo '<a href="' . $large_src[0] . '">';
         echo wp_get_attachment_image($attachment->ID,'medium');
         echo '</a>';
         echo '<p>';
         echo apply_filters( 'the_title', $attachment->post_title );
         echo '</p>';
      }
   }
} ?>
share|improve this answer
    
Missing a ; on about line 3. –  Pat J May 28 '13 at 20:43
    
Thanks @PatJ. Edited –  sprclldr May 28 '13 at 20:46
    
This code adds a link to the thumbnail - "www.mydomen/Array" ?Now the thumbnail does not appear in the lightbox, just running this link - "www.mydomen/Array"... –  Евгений Березовский May 30 '13 at 6:33
    
Don't know why wp_get_image_src returns an array, but I've edited the code to reflect that. I should be returning the source correctly now. –  sprclldr Jun 3 '13 at 18:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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