![](/img/trans.png)
[英]Using localStorage for translations in my website instead of loading them every time i visit the page again
[英]redirect the users based on their ip to a language every time they visit my website with the ability to switch lang after redirection?
我有一個使用 WPML for Multilang 的 Wordpress 站點,我在站點上有三種語言,帶有子目錄選項( /fr、/en、/de )。
示例:如果用戶在德國,我想將他重定向到“/de”,並且仍然讓他能夠切換到另一種語言
我發現了一些像“IP2Location”這樣的插件,但是所有像這樣的插件都會將用戶重定向到他當前的國家語言,並且永遠無法切換到另一種語言
我嘗試通過應用 cookies 來使用 javascript 進行此操作,但這也有問題,它會每天重定向一次用戶,而不是每次他們返回該站點時
您可以使用 wp 操作將此代碼放入 function.php
$referrer = $_SERVER['HTTP_REFERER'];
if (preg_match("/site1.com/",$referrer)) {
header('Location: http://www.customercare.com/page-site1.html');
} elseif (preg_match("/site2.com/",$referrer)) {
header('Location: http://www.customercare.com/page-site2.html');
} else {
header('Location: http://www.customercare.com/home-page.html');
};
?>````
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.