just wondering if I can get the cropped image and also the original of cropped image. Using ACF to build a slider that images are in light box !

 <div class="slide">
    <a href="<?php echo image1_full-sized-image ?>" class="mfp-image">
        <img src="<?php echo image1_cropped-image?>"/>
  • My goal is to cropped images and show them in slider but use the original images in light box !



Yes, it is possible to get original image and a smaller version of it. Use wp_get_attachment_url($id) to get the full url and wp_get_attachment_image_src($id,$size) for the smaller version.

EDIT: You can get the name of the original uncropped (full) image from the attachments post_meta. Then replace the cropped file name with the original name in the full url. If there's more direct way to do this, I'm all ears.

For example like this,

$image_id = 0; // get this from the saved ACF data
$full_image = wp_get_attachment_url( $image_id );
$thumbnail = wp_get_attachment_image_src( $image_id, 'thumbnail' ); // or some other valid image size

// get original file name and replace cropped name with it
$backup_full = get_post_meta( $image_id, '_wp_attachment_backup_sizes', true );
if ( ! empty( $backup_full['full-orig']['file'] ) ) {
    $full_path = explode( '/', $full_image );
    $full_image = str_replace( end( $full_path ), $backup_full['full-orig']['file'], $full_image );

if ( $full_image && is_array( $thumbnail ) ) {
    '<div class="slide">
        <a href="%s" class="mfp-image">
            <img src="%s"/>
    esc_url( $full_image ),
    esc_url( $thumbnail[0] )
  • Thanks for your answer ! Well yes this is working if you get the defined size's as thumbnail, small or large or any other defined. But I want to use cropping tool so each image size can be different from another one ! if I upload and image and crop it free as I want it get's a prefix as image1-e1566822150490.jpg. And know I want to get this image and also the original image as image1.jpg. Any idea for this ? – GMedija Aug 27 '19 at 12:24
  • @GMedija I don't think there's any direct way to get the original uncropped file name. I added one way to get it to my code example. The original file name is saved as post_meta for the attachment, which you can get with get_post_meta(). In my example I just did simple string replacement to get the original file name to the full image url. – Antti Koskinen Aug 27 '19 at 13:18
  • well, thanks for you time ! – GMedija Aug 27 '19 at 14:42
  • @GMedija If my answer solved your question, you can mark it as accepted, thanks! – Antti Koskinen Aug 27 '19 at 14:47

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.