Last active
October 9, 2024 00:33
-
-
Save stefthoen/5890515 to your computer and use it in GitHub Desktop.
WordPress function to create picturefill HTML.
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
function get_responsive_image($id, $src, $alt = "") { | |
$large = wp_get_attachment_image_src( $id, 'large' ); | |
$medium = wp_get_attachment_image_src( $id, 'medium' ); | |
$small = wp_get_attachment_image_src( $id, 'thumbnail' ); | |
$output = '<div class="img-responsive">'; | |
$output.= ' <div data-picture data-alt="' . $alt . '">'; | |
$output.= ' <div data-src="' . $small[0] . '"></div>'; | |
$output.= ' <div data-src="' . $medium[0] . '" data-media="(min-width: 786px)"></div>'; | |
$output.= ' <div data-src="' . $large[0] . '" data-media="(min-width: 920px)"></div>'; | |
$output.= ' <div data-src="' . $src . '" data-media="(min-width: 1140px)"></div>'; | |
$output.= ' <noscript>'; | |
$output.= ' <img src="' . $small[0] . '" alt="' . $alt . '">'; | |
$output.= ' </noscript>'; | |
$output.= ' </div>'; | |
$output.= '</div>'; | |
return $output; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment