Hello,
I recommend reading this post: https://stackoverflow.com/questions/17187437/relative-urls-in-wordpress
Do you know on any plugin using relative urls?
Nevertheless if you really need it applied I have filters set in place that allow you to customize the url, as an example for some CDN: https://www.smart-variations.com/knowledge-base/how-to/adding-cdn-support/
Does it help?
Cheers,
David
Thanks David,
I realize the title of my original post should have been updated. When I first started asking the question, I thought it was just a mobile issue and forgot to update there. Woops.
I haven’t been able to get the filter to work, but I’ll keep messing with it and see if I can figure it out. It was originally throwing an error saying it wanted 4 arguments but only 1 was available. I got it to stop throwing the error by only passing only $image, but then it was still using the site URL and not the ngrok url that I replaced {Insert cdn URL here} with.
Also, as far as I can tell, WooCommerce uses relative URLs for all of it’s images. At least that’s what it shows when I inspect the element of any image that it pulls.
See https://40fc667c.ngrok.io/home/gokey-boots/the-supreme/ for example. The thumbnails pulled for the related products at the bottom are all relative.
It’s not a huge deal, I can set up a staging environment on the site’s cPanel, I was just hoping to be able to share it w/ ngrok.
Thanks again,
Nick
Got it to work!
I had to change your CDN example to:
function svi_cdn_image_url($image)
{
$url = $image[0];
$types = ["gif", "png", "jpg"];
$type = substr($url, -3);
if (in_array($type, $types)) {
$site = get_site_url();
$cdn = "{ngrok URL}";
$image[0] = str_replace($site, $cdn, $url);
}
return $image;
}
add_filter('wp_get_attachment_image_src', 'svi_cdn_image_url');
Interestingly enough, with the filter in place, it adds the ngrok URL to all of the images, even the ones WooCommerce was displaying as relative in my example above. If I remove the filter, they go back to relative.
All good now!
Hi,
just FYI you can see the official storefront theme: https://themes.woocommerce.com/storefront/product/lowepro-slingshot-edge-250-aw/
There is no relative urls :/
Maybe you have something else removing and covnertinf everythign to relative urls.
Cheers,
David
Good call! I just checked out the live version on the site’s real domain and they are all absolute, but when hosted through Desktop Server Pro it removes them. I guess it doesn’t mess w/ the plugin because it’s all done after the fact in javascript.
Thanks for the help!
No problem.
When you have the time would really appreciate a review.
Cheers,
david