Last active
August 29, 2015 14:08
-
-
Save twentyfortysix/07b23e5bd23b160c8a30 to your computer and use it in GitHub Desktop.
WP function
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
// picture ids: array(1, 2, 3) | |
// $queries = array( | |
// array('large_screens','min-width: 1450px'), | |
// array('medium','max-width: 480px'), | |
// array('large','') | |
// ); | |
// $class = class | |
function responsive_picture2($id, $class, $queries){ | |
$with_euery = ''; | |
$without_euery = ''; | |
// if the query has no media query resolution set, print it out as it is | |
foreach($queries as $key => $query){ | |
$att = wp_get_attachment_image_src($id , $query[0]); | |
if(!empty($query[1])){ | |
$with_euery .= '<source srcset="'.$att[0].'" media="('.$query[1].')">'; | |
}else{ | |
$without_euery .= '<img srcset="'.$att[0].'" class="'.$class.'" alt="hohostyle '.$id.'" />'; | |
} | |
} | |
if(!empty($with_euery) || !empty($without_euery)){ | |
$return = '<picture>'.$with_euery."\n".$without_euery."\n".'</picture>'; | |
}else{ | |
$return = ''; | |
} | |
return $return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment