Skip to content

Instantly share code, notes, and snippets.

@besimhu
Last active August 29, 2015 14:17
Show Gist options
  • Save besimhu/3c7ae0b066b6beed1d96 to your computer and use it in GitHub Desktop.
Save besimhu/3c7ae0b066b6beed1d96 to your computer and use it in GitHub Desktop.
// Markup
<img src="<?php echo $src; ?>"
alt="<?php echo $alt; ?>"
width="<?php echo $width; ?>"
height="<?php echo $height; ?>" />
/**
* Pull image through object/array.
*
* This method is similar to pulling through the WP ID function. You do
* end up getting access to more object information, however it's quite a bit
* more writing you have to do.
*
* http://www.advancedcustomfields.com/resources/image/
*/
// Pull image from ACF field.
$image = get_field('image_field');
// Pull object data.
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];
// Define image size through crop.
$size = 'thumbnail';
$src = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment