Created
December 29, 2015 13:30
-
-
Save thebiltheory/e55561d29595d06e4471 to your computer and use it in GitHub Desktop.
Customized function to generates ACF costomized image display.
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
<?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