WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

i have the url of an image (full size). During the upload it already generates a smaller version (i added this in functions). How can i get this cropped version when i have the full size url?

The Image is not in a post so i can't use post-thumbanil() The image is in a slider on the Homepage

share|improve this question
up vote 1 down vote accepted

Get the attachment ID for the image, then get the post meta field _wp_attachment_metadata for it. This is a serialized array. The field sizes in that array contains all available image sizes.


$sizes = array();

$attachment_url  = 'http://examle.com/wp-content-uploads/foo.png';
$attachment_dir  = dirname( $attachment_url );
$attachment_id   = get_attachment_id( $attachment_url );
$attachment_meta = get_post_meta( $attachment_id, '_wp_attachment_metadata', TRUE );

$sizes[] = $attachment_url; // main file

if ( ! empty ( $attachment_meta[ 'sizes' ] ) )
    foreach ( $attachment_meta[ 'sizes' ] as $size )
        $sizes[] = "$attachment_dir/" . $size[ 'file' ];
share|improve this answer
Thank you. I have taken the largest part of your code and I have edited it a little. Now it works perfect – user2416687 Jul 7 '13 at 12:42

Your Answer


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.