You should use wp_get_attachment_image_src then pass the result to the plugin’s function called wr2x_get_retina( $path ), if you can make it work with this it would be simple.
I plan to add an easy to call function that does everything magically. Please ping me if I forget, I will do it when I am back from my holidays π
Hi Jordy!
Thanks for your quick reply π
When I use your function with the URL, it returns NULL?
When I append “@2x” to the URL manually, it works.
Sorry I need more time to write the functions and add them into the documentation. I just gave you a quick reply π
Will add this in the next release.
I fully understand and just wanted to let you know π
Looking forward to the next release, and keep up the sweet work!
Actually, I did π Yesterday’s release!
You can use this info/api:
https://ww.wp.xz.cn/plugins/wp-retina-2x/faq/
I tried using your function like this:
style="background-image:url(<?php echo wr2x_get_retina_from_url($icon); ?>);"
Now it always returns the retina version?
Another problem is that my manually inserted logo:
<img src="<?php echo RIISKIT_BASE_URL . 'img/logo.png'; ?>" alt="<?php echo esc_html( get_bloginfo('name') ); ?>" width="205" height="49" />
β¦doesn’t get rewritten to srcset, even though I’ve a retina version appended with @2x?
Thanks, Chris.
Yes, wr2x_get_retina_from_url would always return the retina version. With caching, we can’t let this function decides if the device is retina or not, that wouldn’t work most of the time. There is no media query inline CSS so your options are a bit limited here… I would keep using wr2x_get_retina_from_url, this is fine. Would end up with bigger image for normal users but that is okay.
I am not sure about the second issue. It should work. Can you turn on the retina logs and check whether or not this img src is detected? The log should give you useful info.
I see. The error message I get from my log is:
The img tag was not rewritten. No retina for 'http://localhost:8888/fagtak/wp-content/themes/riiskit/img/logo.png'.
I do have a [email protected] in the same folder?
Eventually, I ended up writing the srcset manually, but it would still be nice to know what’s wrong.
Are you using the last version of the plugin Christoffer? It seems yes (from what we discussed before) but a few versions ago the theme folder wouldn’t work. Now it does.
But yeah, that should work π