5

I'm adding additional image sizes to my theme:

functions.php

add_image_size( 'my-thumbnails', 122, 122, true );  

I used to get thumbnails URL like this:

wp_get_attachment_url(get_post_thumbnail_id($post->ID)); 

And it works like a charm, but I'm not sure how to display 'my-thumbnails' version of the thumbnail?

This doesn't work:

wp_get_attachment_image_src( get_post_thumbnail_id($post->ID),'my-thumbnails' );  

What's wrong?

2

You should use one of the following:

// Thumbnail
wp_get_attachment_thumb_file( $GLOBALS['post']->ID );

// Custom
wp_get_attachment_image_src( $attachment_id, $size='my-thumbnails' );
// Or:
wp_get_attachment_image( $attachment_id, $size='my-thumbnails' );
  • Shouldn't this be $size='my-thumbnails' instead of $size='thumbnail' to answer the question fully correctly? – Mike Kormendy Aug 19 '16 at 17:36
  • @MikeKormendy thumbnail is the default builtin value – kaiser Aug 19 '16 at 17:42
  • I think we answered the question fully... My comment included. – Mike Kormendy Aug 20 '16 at 20:21
  • You can edit and clean up comments. Comments are not part of the answer and only temp. – kaiser Aug 20 '16 at 20:53
  • @MikeKormendy how about explaining what is the default? – kaiser Aug 22 '16 at 4:49
1

If you're using the thumbnail as a featured image

the_post_thumbnail( 'my-thumbnails' );
0

make your own function in function.php for display your images, then call it and put the size on the parameters of the function.

  • Are you sure there is no other way? – Wordpressor Aug 18 '11 at 23:15
  • well, is the better way, no?, or what do you have in mind? – eveevans Aug 19 '11 at 0:19

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.