Skip to content

Instantly share code, notes, and snippets.

@thebiltheory
Created December 29, 2015 13:30
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 thebiltheory/e55561d29595d06e4471 to your computer and use it in GitHub Desktop.
Save thebiltheory/e55561d29595d06e4471 to your computer and use it in GitHub Desktop.
Customized function to generates ACF costomized image display.
<?php
/**
* Custom function for ACF to display an customized image field.
*
*/
function tabs_image($img){
$image = get_sub_field($img); //replace get_sub_field by get_field if not subfield
if( !empty($image) ):
// vars
$url = $image['url'];
$title = $image['title'];
$alt = $image['alt'];
$caption = $image['caption'];
// thumbnail
$size = 'tabs-thumb';
$thumb = $image['sizes'][ $size ];
$width = $image['sizes'][ $size . '-width' ];
$height = $image['sizes'][ $size . '-height' ];
if( $caption ):
echo '<div class="wp-caption">';
endif;
//Uncomment to create link to image
// echo '<a href="' . $url . '" title="' . $title . '">';
echo '<img src="' . $thumb . '" alt="' . $alt . '" width="' . $width . '" height="' . $height . '" />';
// echo '</a>';
//Uncomment to create link to image
if( $caption ):
echo '<p class="wp-caption-text">' . $caption . '</p>';
echo '</div>';
endif;
endif;
}
?>
<?php
/**
* USAGE:
* Simply compy pase this in your code by replacing the 'your_image_field_name' parameter
*/
echo tabs_image('your_image_field_name'); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment