Created
November 20, 2015 06:29
-
-
Save ThierryA/bb7e2d2fd3152e471359 to your computer and use it in GitHub Desktop.
Beans: simple responsive images example.
This file contains 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 | |
// 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