Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Jordy Meow

    (@tigroumeow)

    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

    (@jynk)

    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×[email protected]&#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/

    Plugin Author Jordy Meow

    (@tigroumeow)

    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.ww.wp.xz.cn/reference/functions/wp_get_attachment_image/
    And the plugin will do the rest 😉

    Thread Starter jynk

    (@jynk)

    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.