Created
October 28, 2015 09:01
-
-
Save yratof/ca460d25863dfc02df66 to your computer and use it in GitHub Desktop.
Image and Mobile image for Advanced custom fields 5 + wordpress mobile
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 | |
$image = get_sub_field('background_image'); | |
// Image related details | |
$img_title = $image['title']; | |
$alt = $image['alt']; | |
$size = 'hero-video'; | |
$thumb = $image['sizes'][ $size ]; | |
$width = $image['sizes'][ $size . '-width' ]; | |
$height = $image['sizes'][ $size . '-height' ]; | |
// Mobile Sizing of images | |
$msize = 'hero-mobile'; // | |
$mthumb = $image['sizes'][ $msize ]; // | |
$mwidth = $image['sizes'][ $msize . '-width' ]; | |
$mheight = $image['sizes'][ $msize . '-height' ]; | |
// Put the images into a variable. Can't be arsed to leave code everywhere, keep it bundled together. | |
$m_img = '<img src="'. $mthumb .'" alt="' . $alt . '" width="' . $width . '" height="' . $height .'" title="' . $img_title . '"/>'; | |
$img = '<img src="'. $thumb .'" alt="' . $alt . '" width="' . $width . '" height="' . $height .'" title="' . $img_title . '"/>'; | |
/* Profile Picture */ if(!wp_is_mobile()){echo $img;} else {echo $m_img;} ?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment