responsify-wp icon indicating copy to clipboard operation
responsify-wp copied to clipboard

lazy load with rwp_edit_generated_element

Open benjamingeorge opened this issue 10 years ago • 2 comments

I tried adding your example filter for lazy loading. In my templates I use rwp_img() to get the picturefill markup but the [data-src] attribute isn't added. Is the rwp_edit_generated_element filter called when using rwp_img() or rwp_picture?

benjamingeorge avatar Sep 18 '15 15:09 benjamingeorge

In rwp_functions.php you can add the filter methods and it seems to work.

function rwp_img( $id, $settings = null ) {
    $element = Picture::create( 'img', $id, $settings );
    if ( has_filter( 'rwp_edit_generated_element' ) ) {
        $element = apply_filters( 'rwp_edit_generated_element', $element );
    }
    return $element;    
}

benjamingeorge avatar Sep 18 '15 15:09 benjamingeorge

Hi! Sorry for the late reply, I've turned off notification mails accidentally ;) No, you're right. The filter is not applied when calling rwp_img() or rwp_picture(). You might be able to use rwp_attributes() instead, but the filter should of course be applied here to.

Thanks for telling me about this :)

stefanledin avatar Sep 21 '15 08:09 stefanledin