Skip to content

Instantly share code, notes, and snippets.

@yellowberri-snippets
Last active December 21, 2015 18:19
Show Gist options
  • Save yellowberri-snippets/6346607 to your computer and use it in GitHub Desktop.
Save yellowberri-snippets/6346607 to your computer and use it in GitHub Desktop.
PHP: ACF: Basic Image Field
if ( get_field('image') ) {
$image = get_field('image');
// Some useful keys.
// $image['url'] - Full size image.
// $image['sizes']['medium'] - Medium size image.
// $image['alt'] - Image Alternative text field.
// $image['title'] - Image title field.
// $image['caption'] - Image caption field.
// If no Alt Text is found replace it with nothing, so at least you have a blank attribute.
$image['alt'] = ( empty($image['alt']) ? "\x20" : $image['alt'] );
echo "<img src='" . $image['sizes']['medium'] . "' alt='" . $image['alt'] . "'>";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment