Replace some images
-
Hi, I need exclude some images (by ID for example) from CDN. What filters do you use to change the original image to the CDN image? I thought they use wp_get_attachment_url or wp_calculate_image_srcset but they don’t work.
-
This topic was modified 2 years, 8 months ago by
jeiriart.
-
This topic was modified 2 years, 8 months ago by
-
Dear @jeiriart
All the CPU-intensive optimizations are performed by RabbitLoader cloud servers, thus reducing the usage of your hosting resources. Due to this, some WP filters may not work.
There are many ways by which you can exclude images from getting optimized by RabbitLoader, and the easiest one is by adding a data attribute
data-rlskip="1"to any IMG tag.Other ways are explained in this KB -https://rabbitloader.com/kb/exclude-images-from-lazy-loading/
Hi, yes, that works, but the images are backgrounds, we need to be able to intervene the hook that loads them, in this case “wp_calculate_image_srcset” does not work because it is for images with “figure” or “img” tags and we discard it since for backgrounds this hook does not work. In the administration panel works “wp_get_attachment_url” but not in the frontoffice. How do you replace the image then if not with hooks?
Thanks
-
This reply was modified 2 years, 8 months ago by
jeiriart.
Dear @jeiriart Please provide us the webpage URL and Image URL that you wish to exclude from CDN. I will analyze and suggest the most suitable approach.
My problem is that your cdn shrinks the size of the image to 1920px wide, this makes the design break on some screens, so we want to be able to remove those particular images from the cdn. Problem 1: they are changing all the time and there are always new ones, we need to be able to do it ourselves. Problem 2: we need to be able to do it from the WordPress backoffice.
Web: https://arcorencasa.com/bagley/
Image: https://cfw.rabbitloader.xyz/eyJjIjp0cnVlLCJoIjoiYXJjb3JlbmNhc2EuY29tIiwidiI6MjcwMzc0NjM2Mn0/wp-content/uploads/2023/07/seccion-fondo-bagley-rojo2.png (is a background)Dear @jeiriart thank you for the details. It gave me a fair picture of what is happening.
If we allow adding a GET parameter to the image URL, for example,
img.png?rl-resize=0to prevent resizing particular images, will that solve your purpose? If it does, the next thing would be to intercept the inline CSS injected insideporto-style-inline-cssthat holds this backgorund-image. Do you know if the source of this inline CSS has any hooks to append this new GET parameter to the end of the image URL?Hi, no, this is built with WPBakery, so there are no hooks to intercept the css. We need to be able to intercept the image directly, but I understand it is not possible to do this?
Did you try checking with the WPBakery team if there is a way to append parameters to the Image URL?
RabbitLoader can help you with these options, I have summarized all options here to keep track of them-
- by setting its class name in the Page Rule. (not applicable here because it’s a background image)
- by setting the image file name in Page Rule. (feature does not exist now but is feasible)
- by setting a GET parameter in the image URL (aka
img.png?rl-resize=0) through PHP code. (Depends if it’s possible to do via WPBakery) - by using an image that comes from a different host than the website (for example S3, or other image hosting service). RabbitLoader does not touch images from other origins than the actual website.
We are open to suggestions if you can think of other possibilities.
Hi, the theme is Portos, and this: ?rl-resize=0 was the solution
thanks!perfect 😀 I am glad that it helped.
-
This reply was modified 2 years, 8 months ago by
The topic ‘Replace some images’ is closed to new replies.