更改标题中的 WordPress 链接 [英] Changing WordPress link in header
问题描述
我制作了一个网站,其中安装了 2 个 WordPress,一个用于英语,另一个用于爱尔兰语.它们是具有相同类别、页面名称等的相同设置.
I have made a website that has 2 WordPress installs one for English language and one for Irish language. They are identical setups with same categories, page names etc.
我有'英语|在我的每页页眉中的爱尔兰语链接.
I have 'English | Irish' links in my header on each page.
当您在英文页面上单击顶部的爱尔兰"链接时,我希望它能够将您带到同一页面,但位于爱尔兰网站上.
When you are on the english page and you click the 'irish' link at top I would like it to take you to the same page but on the Irish site.
链接结构如下图:
http://mysite.com/english/about
所以我真的只需要将 url 中的 'english' 替换为 'irish'
So I really only need 'english' in the url to be replaced by 'irish'
推荐答案
它们是标准的 wordpress 插件,可为您处理多语言问题.但是,如果您想留下来,请选择此脚本完全符合您的要求.
Their are standard wordpress plugins that handle multi-language issue's for you. But if you whant to stay with you choise this script does exactly what you asked.
$url = 'http://www.mysite.com/english/about/me/test';
$parsedUrl = parse_url($url);
$path_parts = explode("/",$parsedUrl[path]);
$newUrl = $parsedUrl[scheme] . "://" . $parsedUrl[host];
foreach($path_parts as $key =>$part){
if($key == "1"){
if($part == "english") $newUrl .= "/irish";
else $newUrl .= "/english";
} elseif($key > "1"){
$newUrl .= "/" . $part;
}
}
echo "Old: ". $url . "<br />New: " .$newUrl;
这篇关于更改标题中的 WordPress 链接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!