sybrew/the-seo-framework

Polylang: Wrong canonical URL for non-default language's homepage

Closed this issue · 1 comments

When "WP Admin > Settings > Reading," "Your homepage displays" is set to "Your latest posts," using Polylang, the homepage always shows the canonical URL of the primary language, even when accessing another language's homepage.

Previous: #392.

This issue affects all sites, regardless of which setting. This is because the home_url() isn't augmented by Polylang when the plugin isn't "whitelisted."

From TSF v5.0, we started the plugin's augmentation at parse_request instead of template_direct. This solved a host of compatibility and performance issues, but Polylang is affected. To learn more, see polylang/polylang#1422.

  1. We could hijack their filter and allow all home_url() to almost always be translated, regardless of a "whitelist" or "blacklist." This would make Polylang perform nearly twice as fast. See WPML_URL_Filters::home_url_filter(), which works perfectly. They only block REST, pagination links, and WP_Rewrite::rewrite_rules(). The last one is probably what Polylang also found to cause issues, so they forced the home_url() augmentation to only work on the front-end via template_redirect, with an additional layer to allow only tested functions to work. This must forever be maintained, which is indicative of why we're always facing issues with Polylang but never WPML.
  2. Polylang could also move the augmentation up to parse_request from template_loaded. It holds its intended effect but runs earlier, allowing third-party developers more freedom.