Guest User

Untitled

a guest
Jun 23rd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.10 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. * Returns a responsive img tag for 'page_image'
  5. * This is usually positioned at top of content_column (default template, news detail, etc)
  6. * img_id = ID of the image
  7. */
  8.  
  9. function make_responsive_page_img($image_id) {
  10. if($image_id ){
  11. // Check the attachment exists
  12. if(wp_get_attachment_image_url($image_id) === false) {
  13. return false;
  14. }
  15.  
  16. $mobile_img_src = wp_get_attachment_image_url( $image_id, 'page-mobile' );
  17. $tablet_img_src = wp_get_attachment_image_url( $image_id, 'page-tablet' );
  18. $desktop_img_src = wp_get_attachment_image_url( $image_id, 'page-desktop' );
  19. $alt = get_the_title($image_id);
  20.  
  21. $image = '
  22. <img
  23. class="page-image"
  24. alt="' . $alt . '"
  25. src="' . $desktop_img_src . '"
  26. srcset="
  27. ' . $mobile_img_src . ' 320w,
  28. ' . $tablet_img_src . ' 768w,
  29. ' . $desktop_img_src . ' 950w"
  30. >
  31. ';
  32. return $image;
  33. }
  34. }
Add Comment
Please, Sign In to add comment