Support

Account

Home Forums ACF PRO LazyLoad fail with images from WYSIWYG field

Unread

LazyLoad fail with images from WYSIWYG field

  • Hello!

    I have a LazyLoad script that works on all the WP images.
    It works great on default content field, images and gallery ACF Fields, but it fails on WYSIWYG ACF field.

    I think the issue is with this (located on function.php):

    // Data src
    add_filter( 'wp_get_attachment_image_attributes', 'gs_change_attachment_image_markup' );
    /**
     * Change src and srcset to data-src and data-srcset, and add class 'lazyload'
     * @param $attributes
     * @return mixed
     */
    function gs_change_attachment_image_markup($attributes, $attachment, $size){
    
        if (isset($attributes['src'])) {
            $attributes['data-src'] = $attributes['src'];
            $attributes['src']      = ''; //could add default small image or a base64 encoded small image here
        }
        if (isset($attributes['srcset'])) {
            $attributes['data-srcset'] = $attributes['srcset'];
            $attributes['srcset'] = '';
        }
        //$attributes['data-adaptive-background'] .= '1';
    
        return $attributes;
    
    }

    It replace the src attribute by a data-src (which is used by the LazyLoad script).
    I think it is not working on iages from WYSIWYG ACF field.

    Any ideas?

Viewing 1 post (of 1 total)

The topic ‘LazyLoad fail with images from WYSIWYG field’ is closed to new replies.