This seems to do the trick. Put this code in a plugin.
add_filter('pll_redirect_home', 'no_home_redirection');
add_filter('pll_check_canonical_url', 'no_home_redirection_canonical', 10, 2);
function no_home_redirection($redirect) {
return false;
}
function no_home_redirection_canonical($redirect_url, $language) {
if (is_front_page()) {
error_log('no_home_redirection_canonical');
return false;
} else {
return $redirect_url;
}
}
Plugin Author
Chouby
(@chouby)
Hi!
I would expect that only the first filter is necessary.
Are you using v1.7.2?
Could you precise your permalinks and Polylang settings and if you are using a static front page?
Hi!
Thanks for answering.
Yes, I use 1.7.2.
Permalinks: “Post name”
Using a static front page (not blog posts)
Polylang options:
s:7:"browser";i:0;
s:7:"rewrite";i:1;
s:12:"hide_default";i:0;
s:10:"force_lang";i:1;
s:13:"redirect_lang";i:0;
s:13:"media_support";i:0;
s:4:"sync";a:0:{}
s:10:"post_types";a:0:{}
s:10:"taxonomies";a:0:{}
s:7:"domains";a:0:{}
s:7:"version";s:5:"1.7.2";
s:12:"default_lang";s:2:"fr";
Using only pll_redirect_home causes requests for the front page (at wordpress root http://www.foo.com/wordpress) to be redirected (301) to http://www.foo.com/wordpress/fr/ (default language) or another language depending on the client language cookie.
Adding the second (undocumented) filter pll_check_canonical_url makes sure requests for the wordpress root do not get redirected.
By the way, during tests, I just noticed that Polylang doesn’t seem to respect the trashed status of a page, at least in the case of the front page. I had a trashed English translation of the front page and Polylang was redirecting to it and producing a 404.
Plugin Author
Chouby
(@chouby)
Thanks for the options. I agree that in that specific case you need to act on both filters.
By the way, during tests, I just noticed that Polylang doesn’t seem to respect the trashed status of a page, at least in the case of the front page.
When using a static front page, Polylang mandatorily needs that it is translated in all languages.