Title: correct code and function when using wp_get_attachment_image_src
Last modified: August 31, 2016

---

# correct code and function when using wp_get_attachment_image_src

 *  [jynk](https://wordpress.org/support/users/jynk/)
 * (@jynk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/correct-code-and-function-when-using-wp_get_attachment_image_src/)
 * We use wp_get_attachment_image_src and build our own <img> for a number of reasons.
 * What do we need to do to get the image tag working correctly with retain images?
   What attributes are required and how are they populated?
 * Thanks!
 * [https://wordpress.org/plugins/wp-retina-2x/](https://wordpress.org/plugins/wp-retina-2x/)

Viewing 4 replies - 1 through 4 (of 4 total)

 *  Plugin Author [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * (@tigroumeow)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/correct-code-and-function-when-using-wp_get_attachment_image_src/#post-7177026)
 * Hello,
 * You actually don’t need to do anything, just use wp_get_attachment_image_src,
   and as long as you have an img tag in your code the plugin will rewrite it nicely
   with a srcset like it is supposed to be. You didn’t try that?
 *  Thread Starter [jynk](https://wordpress.org/support/users/jynk/)
 * (@jynk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/correct-code-and-function-when-using-wp_get_attachment_image_src/#post-7177027)
 * Hey Jordy – there’s no scrset being added so just wanted to see if theres a simple
   way of adding it?
 *     ```
       <?php
       $im_id =$slide['ID'];
       $is_retina = get_pixel_ratio();
       $image_src = wp_get_attachment_image_src( $im_id ,'large');
       $image_src_fullsize = wp_get_attachment_image_src( $im_id ,'fullsize');
       $alt = get_post_meta($im_id, '_wp_attachment_image_alt', true);
       $ret_img = wr2x_get_retina_from_url( $image_src[0] );
       ?>
        <img src="<?=$image_src[0]?>" width="<?=$image_src[1]?>" class="<?=$image_src[1]?> retina_<?=$is_retina?> <?=($ret_img!='' ? 'retina_has_src' : 'retina_no_src')?>" data-lazy="<?=($ret_img!='' ? $ret_img: $image_src_fullsize[0])?>" alt="<?=$alt ?>" />
       ```
   
 * generates –
    <img src=”[http://dmfkdev.jynk.net.local/sitecontent/wp-content/uploads/2016/01/dMFK-architects-London-fitout_construction_offices_communal_working_kajima_baker_street_london_PS_9884-634×810@2x.jpg&#8221](http://dmfkdev.jynk.net.local/sitecontent/wp-content/uploads/2016/01/dMFK-architects-London-fitout_construction_offices_communal_working_kajima_baker_street_london_PS_9884-634×810@2x.jpg&#8221);
   width=”626″ class=”634 retina_2 retina_has_src” alt=”” style=”width: auto; height:
   800px; opacity: 1;” height=”800″ scale=”2″>
 * [http://dmfk.co.uk/projects/brondesbury-park/](http://dmfk.co.uk/projects/brondesbury-park/)
 *  Plugin Author [Jordy Meow](https://wordpress.org/support/users/tigroumeow/)
 * (@tigroumeow)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/correct-code-and-function-when-using-wp_get_attachment_image_src/#post-7177029)
 * The function wr2x_get_retina_from_url does exactly what is says, it returns the
   retina image if there is one for a given URL to the image.
 * The plugin works automatically, except if you know exactly what you are doing
   and why, you don’t have to use this function or anything related to the plugin.
 * The best is to use this function:
    [https://developer.wordpress.org/reference/functions/wp_get_attachment_image/](https://developer.wordpress.org/reference/functions/wp_get_attachment_image/)
   And the plugin will do the rest 😉
 *  Thread Starter [jynk](https://wordpress.org/support/users/jynk/)
 * (@jynk)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/correct-code-and-function-when-using-wp_get_attachment_image_src/#post-7177032)
 * Yes i know what wr2x_get_retina_from_url does and that’s why i’m using it.
 * Retina’s lazy loading won’t work with the slick slideshow (or visa/versa) which
   is why i wanted to control the structure of the <IMG> and find a way of using
   either slick’s lazy loading, retina’s or just try and use the scrset or all 3.
   I’m still to test scrset so was wondering if there’s a function that builds it
   and can include the retina versions too?
 * Some of these pages are 25mb+ once the retinas are loaded so trying to keep that
   down until the user acts to view them.

Viewing 4 replies - 1 through 4 (of 4 total)

The topic ‘correct code and function when using wp_get_attachment_image_src’ is 
closed to new replies.

 * ![](https://ps.w.org/wp-retina-2x/assets/icon-256x256.png?rev=2597316)
 * [Perfect Images: Regenerate Thumbnails, Image Sizes, WebP & AVIF](https://wordpress.org/plugins/wp-retina-2x/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/wp-retina-2x/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/wp-retina-2x/)
 * [Active Topics](https://wordpress.org/support/plugin/wp-retina-2x/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/wp-retina-2x/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/wp-retina-2x/reviews/)

## Tags

 * [img](https://wordpress.org/support/topic-tag/img/)
 * [lazy](https://wordpress.org/support/topic-tag/lazy/)

 * 4 replies
 * 2 participants
 * Last reply from: [jynk](https://wordpress.org/support/users/jynk/)
 * Last activity: [10 years, 2 months ago](https://wordpress.org/support/topic/correct-code-and-function-when-using-wp_get_attachment_image_src/#post-7177032)
 * Status: not resolved