Permalink update process by Polylang – Please explain
-
Hello Chouby,
Still trying to understand how Polylang proceed.
As discussed ealier (https://ww.wp.xz.cn/support/topic/getting-language-from-path; https://ww.wp.xz.cn/support/topic/order-of-hookfilter-execution), I am trying to execute a code to switch language from an URL parameter lang.
I thought it was working but I was wrong. I really – and quickly – need to understand how Polylang is adding/replacing the language slug in permalink and how it tells worpress to reconsider the permalink.
NOTE: I am not concerned by rewrites anymore.
My URL:
www.next.ca/dl?lang=fr
A rewrite rule:function dl_rewrite_rules() { add_rewrite_rule( 'dl.*', 'index.php?pagename=dl', 'top' ); } add_action( 'init', 'dl_rewrite_rules' );So far, I have this:
1) Polylang scans the URL and does not find a language code (en|fr), so it sets language to default (en) and fires “pll_language_defined”.
2) My function below is executed. It gets the lang parameter and if the lang parameter is present, changes the language by setting $polylang->curlang.
function detectDLPageLanguage() { //Hooked on PLL event, no need to check PLL existence //Over simplified code global $polylang; // $_GET['lang'] == 'en' or 'fr' $polylang->curlang = $polylang->model->get_language($_GET['lang']); } add_action('pll_language_defined', 'detectDLPageLanguage');At this point, only the current language has changed.
What happens next?
My goal is to get the permalink to be modified from
www.next.ca/dl?lang=frtowww.next.ca/fr/dl?lang=fr
but actualy does not. Whatever I do it simply goes to default language,www.next.ca/en/dl?lang=fr.Is there extra instructions I should give Polylang to update the permalink according the updated $polylang->curlang?
Is there other hook(s) involved?Please advise,
Thanks
The topic ‘Permalink update process by Polylang – Please explain’ is closed to new replies.