Created
August 27, 2015 12:21
-
-
Save mattradford/1cb6d7d882b907cb1f55 to your computer and use it in GitHub Desktop.
ACF - display image and alt text
This file contains hidden or 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
(1) | |
<?php | |
$imageArray = get_field('footer_logo', 'options'); | |
$imageAlt = $imageArray['alt']; | |
$imageURL = $imageArray['sizes']['thumbnail']; | |
?> | |
<img src="<?php echo $imageURL;?>" alt="<?php echo $imageAlt; ?>"> | |
(2) | |
<?php | |
$imageArray = get_sub_field('image'); | |
$imageAlt = $imageArray['alt']; | |
$imageURL = $imageArray['sizes']['medium']; | |
echo '<img src="'.$imageURL.'" alt="'.$imageAlt.'">'; | |
?> | |
(3) | |
<?php | |
$imageArray = get_field('header_image'); | |
$imageURL = $imageArray['url']; | |
?> | |
<div class="page-header" style="background-image: url('<?php echo $imageURL;?>');"> | |
And on a taxnomomy archive page: | |
<?php | |
// vars | |
$queried_object = get_queried_object(); | |
$taxonomy = $queried_object->taxonomy; | |
$term_id = $queried_object->term_id; | |
// load thumbnail for this taxonomy term (term object) | |
$imageArray = get_field('image', $queried_object); | |
$imageURL = $imageArray['url']; | |
?> | |
<div class="page-header" style="background-image: url('<?php echo $imageURL;?>');"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment