Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- * Returns a responsive img tag for 'page_image'
- * This is usually positioned at top of content_column (default template, news detail, etc)
- * img_id = ID of the image
- */
- function make_responsive_page_img($image_id) {
- if($image_id ){
- // Check the attachment exists
- if(wp_get_attachment_image_url($image_id) === false) {
- return false;
- }
- $mobile_img_src = wp_get_attachment_image_url( $image_id, 'page-mobile' );
- $tablet_img_src = wp_get_attachment_image_url( $image_id, 'page-tablet' );
- $desktop_img_src = wp_get_attachment_image_url( $image_id, 'page-desktop' );
- $alt = get_the_title($image_id);
- $image = '
- <img
- class="page-image"
- alt="' . $alt . '"
- src="' . $desktop_img_src . '"
- srcset="
- ' . $mobile_img_src . ' 320w,
- ' . $tablet_img_src . ' 768w,
- ' . $desktop_img_src . ' 950w"
- >
- ';
- return $image;
- }
- }
Add Comment
Please, Sign In to add comment