In my page templates I’m including an image using the image field, like this:
<?php
$image = get_field('img');
echo '<img src="' . $image['sizes']['large'] . '" alt="' . $image['alt'] . '" />';
?>
I’d like to automatically wrap those images with a link to the full-size media file, just like when inserting images using the default WP WYSIWYG editor and selecting “Link To: Media File”.
So the html output would be something like:
<a href="../link-to-media-file.jpg">
<img src="../media-file.jpg" alt="alt-text" >
</a>
This is probably really simple, and maybe I’m overlooking the obvious, but somehow I’m not coming up with a solution.
According to the documentation try
As opposed to Volker’s answer, try this:
It’s a little tidier and easier to read through, and it outputs the exact same thing.
Check the documentation for more info.