WordPress – Link custom thumbnail to full sized attachment image

I’m coding a custom theme and I want to link a custom sized thumbnail image to the full size (or large) version of the image.

The code I’m using is:

Read More
<?php 
$attachment_id = get_field('main_product_photo');
$size = "main-product-thumb"; // (thumbnail, medium, large, full or custom size)
wp_get_attachment_image( $attachment_id, $size ); 
$image = wp_get_attachment_image_src( $attachment_id, $size );
// url = $image[0];
// width = $image[1];
// height = $image[2];
?>
<a href="<?php echo $image[0]; ?>"><img src="<?php echo $image[0]; ?>"></a>

However, this just links to my thumbnail sized image. Does anyone have a quick fix for this? Thanks!

Related posts

Leave a Reply

1 comment

  1. <?php 
    $attachment_id = get_field('main_product_photo');
    $size = "main-product-thumb"; // (thumbnail, medium, large, full or custom size)
    wp_get_attachment_image( $attachment_id, $size ); 
    $image = wp_get_attachment_image_src( $attachment_id, $size );
    $post_thumbnail_url = wp_get_attachment_url( $attachment_id  );
    // url = $image[0];
    // width = $image[1];
    // height = $image[2];
    ?>
    <a href="<?php echo $post_thumbnail_url; ?>"><img src="<?php echo $image[0]; ?>"></a>