grappler/polylang-slug

Redirect to default languages url

Closed this issue · 7 comments

Hi. I tried to use your plugin. Need the same slug for different languages.
Installed plugin. Created 2 pages with the same slug, but have redirection from
http://tour.wss.pp.ua/en/step-2/
to
http://tour.wss.pp.ua/step-2/

Can you help to solve the problem?

I have the same issue.
The main problem is polylang does not add the lang parameter to the rewrite rules for pages. On the other hand WordPress uses a different method to load pages compared to posts. (get_page_by_path())
So we need to modify the rewrite rules to get the lang parameter and hook into pre_get_posts to force the right page.
I've created a "quick and dirty" solution to fix this for my needs. It may have side effects but in my settup it works like a charm.
You can test it if you like:
https://github.com/mirsch/polylang-slug/tree/fixpages

Thank you, mirsch!!! LIKE A CHARM!
grappler, mirsch you are the gods.
Thx men.

@grappler have you looked into this? Should I create a pull request?

I am still looking into it. For some reason it was working for me on one site.

I have been testing some old code that I removed but it is failing and I am not sure why. dbf0590

I'm not sure if this worked in previous versions of polylang, but in the current version there is no lang parameter in the rewrite rules for pages. It looks something like that: [(en)/(.?.+?)(/[0-9]+)?/?$] => index.php?pagename=$matches[2]&page=$matches[3] thats why pll_current_language() always returns the default language for pages. Without any parameter which indicates the language it's not possible to select the right page.

@mirsch & @seokomail Can you try with the latest version? A friend made a PR which should fix the issue.

@arpa463x thank you, but give the Kudos to @grappler! He's the one who wrote and maintain the plugin.