Support » Plugin: WP Retina 2x » How to get srcset in ajax response

  • Resolved marusic

    (@marusic)


    <img src="<?php $src = wp_get_attachment_image_src(get_field('photo'),'gallery-thumb'); echo $src[0]; ?>">

    This code in my template results in nice srcset with normal and @2x image url (get_field is just a function from ACF plugin which returns image id).

    However, that same code in my ajax request for getting more posts stays normal src.

    Is there a function or filter which will replace all srcs in my ajax response html with appropriate srcsets? Is there anything else I need to do after the html is written to page? (e.g. window.polyfill();)

    https://wordpress.org/plugins/wp-retina-2x/

Viewing 2 replies - 1 through 2 (of 2 total)
  • Ok, found it… if anyone needs this, it’s wr2x_picture_rewrite($content); 🙂

    Plugin Author Jordy Meow

    (@tigroumeow)

    Hello 🙂

    Good job, haha ! 🙂 What do you want to use this for? Be careful not to call this in an ajax request or something, this function is not too fast, or the result should be cached.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to get srcset in ajax response’ is closed to new replies.