Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Background-image lazy-loading not compatible with WPML #6178

Closed
webdev69420 opened this issue Sep 19, 2023 · 4 comments · Fixed by #6191
Closed

Background-image lazy-loading not compatible with WPML #6178

webdev69420 opened this issue Sep 19, 2023 · 4 comments · Fixed by #6191
Assignees
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [S] 1-2 days of estimated development time module: lazyload background css images priority: high Issues which should be resolved as quickly as possible severity: major Feature is not working as expected and no work around available type: bug Indicates an unexpected problem or unintended behavior
Milestone

Comments

@webdev69420
Copy link

webdev69420 commented Sep 19, 2023

When using the new CSS background images lazy-loading feature (tested using WP Rocket 3.15.0.1), the background-images do not appear anymore, because the path to them generated by WP-Rocket is incorrect when using WPML on the website.

Here's the original CSS coming from the style.css file present inside the WordPress theme folder:

background: url('/wp-content/themes/themename/img/arrow-right.svg');

Here's the CSS variable generated by WP Rocket, which contains an URL with the wrong path:

--wpr-bg-b1edba74-111c-42a4-8e0e-8b5ff1c99ef1: url('https://www.example.com/fr//wp-content/themes/themename/img/arrow-right.svg');

Wrong URL:

  • https://www.example.com/fr//wp-content/themes/themename/img/arrow-right.svg

What the URL should be:

  • https://www.example.com/wp-content/themes/themename/img/arrow-right.svg'

I guess this problem is coming from WPML adding a virtual directory at the end of the domain name.

But nevertheless, couldn't this easily be detected by WP Rocket?

Steps to reproduce

  • Define a background image in the style.css file of your theme
  • Use a relative path background: url('/your-path/.../image.jpg);
  • Have the CSS background image lazy-loading feature enabled in WP Rocket 3.15.0.1
  • Use WPML with the following URL structure: example.com/[LANG ISO CODE]/your-path/
@Mai-Saad
Copy link

Mai-Saad commented Sep 19, 2023

Can reproduce the problem with the following steps (links give 404):

  1. WPML directory base setup (or qs base setup)
  2. Page template with internal/external BG added to sublanguage
  3. Enable LL BG image
  4. visit the sublanguage version of the page
    => While qs setup, internal relative URLs are rewritten to https://new.rocketlabsqa.ovh/?lang=ar/wp-content/rocket-test-data/images/test-internal1.png , whereas, for directory base setup, internal relative images are rewritten to url('https:\/\/new.rocketlabsqa.ovh\/ar\/wp-content\/rocket-test-data\/images\/test-internal1.png')
  1. WPML domain base setup
  2. Page template with internal/external BG added to sublanguage
  3. Enable LL BG image
  4. visit the sublanguage version of the page
    => External CSS file rewritten to <link rel="stylesheet" href="https://ar.rocketlabsqa.ovh/wp-content/cache/background-css/ar.ar.rocketlabsqa.ovh/wp-content/rocket-test-data/styles/lazyload_css_background_images.css?wpr_t=1695137316">

@Mai-Saad Mai-Saad added type: bug Indicates an unexpected problem or unintended behavior priority: high Issues which should be resolved as quickly as possible severity: major Feature is not working as expected and no work around available module: lazyload background css images and removed needs: testing labels Sep 19, 2023
@Mai-Saad Mai-Saad added the 3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting label Sep 20, 2023
@piotrbak piotrbak added this to the 3.15.2 milestone Sep 21, 2023
@mostafa-hisham mostafa-hisham added the GROOMING IN PROGRESS Use this label when the issue is currently being groomed. label Sep 25, 2023
@mostafa-hisham
Copy link
Contributor

Reproduce the problem ✔️

i was able to reproduce the problem locally using this template

Identify the root cause

WPML plugin changes the output of home_url() and adds the currently used language to it.

Scope a solution

We need to not use home_url() and use get_option( 'home' ) instead to get the URL without the language
in the following locations

return home_url() . '/' . trim( $url, '/ ' );

$home_host = wp_parse_url( home_url(), PHP_URL_HOST );

$values [] = home_url() . $string;

Estimate the effort

Effort S

@mostafa-hisham mostafa-hisham added effort: [S] 1-2 days of estimated development time and removed GROOMING IN PROGRESS Use this label when the issue is currently being groomed. needs: grooming labels Sep 25, 2023
@CrochetFeve0251
Copy link
Contributor

This seems good to me.

@Tabrisrp
Copy link
Contributor

We have a function rocket_get_home_url() to get the home URL with no WPML filters (it's in inc/functions/i18n.php)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3rd party compatibility Issues related to 3rd party compatibility like theme, plugin or hosting effort: [S] 1-2 days of estimated development time module: lazyload background css images priority: high Issues which should be resolved as quickly as possible severity: major Feature is not working as expected and no work around available type: bug Indicates an unexpected problem or unintended behavior
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants