Last active
December 21, 2015 18:19
-
-
Save yellowberri-snippets/6346607 to your computer and use it in GitHub Desktop.
PHP: ACF: Basic Image Field
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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