Skip to content

Instantly share code, notes, and snippets.

@ThierryA
Created November 20, 2015 06:29
Show Gist options
  • Save ThierryA/bb7e2d2fd3152e471359 to your computer and use it in GitHub Desktop.
Save ThierryA/bb7e2d2fd3152e471359 to your computer and use it in GitHub Desktop.
Beans: simple responsive images example.
<?php
// Do not include the opening php tag if it is already included in your file.
add_action( 'beans_post_body_prepend_markup', 'beans_child_reponsive_image_sample' );
function beans_child_reponsive_image_sample() {
$src = 'http://images.apple.com/euro/ipad-mini-4/a/screens_alt/images/overview/hero_large.png';
$small = beans_edit_image( $src, array(
'resize' => array( 465, false ),
), 'OBJECT' );
$medium = beans_edit_image( $src, array(
'resize' => array( 650, false )
), 'OBJECT' );
?>
<picture>
<source media="(max-width: <?php echo $small->width; ?>px)" srcset="<?php echo $small->src; ?>">
<source media="(max-width: <?php echo $medium->width; ?>px)" srcset="<?php echo $medium->src; ?>">
<img src="<?php echo $src; ?>" alt="a cute kitten">
</picture>
<?php
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment