Skip to content

Instantly share code, notes, and snippets.

@mattradford
Created August 27, 2015 12:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mattradford/752cb70a210fcd391e2b to your computer and use it in GitHub Desktop.
Save mattradford/752cb70a210fcd391e2b to your computer and use it in GitHub Desktop.
ACF - display image and alt text
(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