Images Loaded with AJAX Not Displaying in Next-Gen Format
-
Hello,
I am using the <picture> tag to load images in next-gen formats. This works perfectly for images that load during the initial page load.
However, I am encountering an issue with images that are loaded via AJAX when using the “Load More” functionality on my portfolio grid. These images do not appear in the next-gen format (e.g., WebP) but instead revert to the original formats (e.g., JPEG or PNG).
To load the images, I am using the wp_get_attachment_image() function, which should ideally generate the <picture> tag with both WebP and fallback formats for all image requests. This works well initially, but fails to apply during the AJAX calls.
Details of the Current Setup:
? Using <picture> tag to load images in next-gen formats.
? Images are correctly output in next-gen formats on initial page load using wp_get_attachment_image().
? The “Load More” button triggers an AJAX call via admin-ajax.php to fetch additional portfolio items.
? The images loaded through this AJAX request are not being served in the next-gen format, even though they are being loaded with wp_get_attachment_image().
My Question:
Is there a way to ensure that images loaded via AJAX using wp_get_attachment_image() are also served in the next-gen formats? How can I make sure that AJAX-loaded images get the same optimization as those loaded initially?
Thank you,
- The topic ‘Images Loaded with AJAX Not Displaying in Next-Gen Format’ is closed to new replies.