Support » Plugin: Lazy Loader » no output on wp_get_attachment_image()

  • Hey great Plugin!

    If I used the function wp_get_attachment_image() (because I use ACF Image) no output of your plugin will get.
    How do I get the correct output with wp_get_attachment_image() or with another wp function?

    I have a little workaround for this Problem without noscript. On Template I using this:
    echo wp_get_attachment_image( $imageID, $imagesize, false, array("class" => "lazyload", "alt" => $imagecontent) );

    And in my functions.php

    /**
    * Replace src with data-srcset for wp_get_attachment_image() 
    */
    function attachment_image_replace_srcset($attr) {
      /**
       * Add data-sizes and data-srcset attribute.
       */
      $attr['data-srcset'] = $attr['srcset'];
      $attr['data-sizes']  = $attr['sizes'];
      /**
       * Remove sizes and srcset attribute.
       */
      unset( $attr['srcset'] );
      unset( $attr['sizes'] );
    
      return $attr;
    }
    add_filter( 'wp_get_attachment_image_attributes', 'attachment_image_replace_srcset');
    
Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author Florian Brinkmann

    (@florianbrinkmann)

    Hey!

    Great to hear that you like the plugin 🙂

    »If I used the function wp_get_attachment_image() (because I use ACF Image) no output of your plugin will get.«

    Yes, that is (unfortunately) the wanted behaviour of the plugin… WordPress does not provide a way to filter the HTML for these images, so I have no chance to add a noscript fallback automatically… There is a ticket for that (https://core.trac.wordpress.org/ticket/27399), and if that is fixed, I will add the functionality to the plugin. Until then, there is nothing I can do there, sorry…

    Kind regards,
    Florian

    Thread Starter Matthias Honert

    (@matthias-honert)

    Ah thx Florian. 4 years, uff :/
    Then I hope this simple filter will come soon…

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘no output on wp_get_attachment_image()’ is closed to new replies.