简体   繁体   English

通过更改链接中的URL链接到Wordpress移动网站中的确切页面

[英]Link to exact page in Wordpress mobile site by changing url in link

I have a Wordpress main site, and a Wordpress mobile site. 我有一个Wordpress主站点和一个Wordpress移动站点。 All the url slugs are exactly the same on both sites, except that the mobile site has m. 除了移动站点上有m.之外,所有两个站点上的所有url标记都完全相同m. in front. 在前。 I want to let users switch from an exact page on the main site to the mobile site by clicking on one link: 我想让用户通过单击一个链接从主站点上的确切页面切换到移动站点:

<a href="somescript">Mobile Site /a> -> Clicking on this link brings a user from

http://example.com/a-page-1 to http://m.example.com/a-page-1 http://example.com/a-page-1http://m.example.com/a-page-1

For the script in the href, I tried many things but it just didn't work. 对于href中的脚本,我尝试了很多方法,但是没有用。

<?php echo 'm. ' . window.location.href; ?>

href=javascript(var $a=window.location.href;$b='m. '.$a;return $b;)

For everything I tried, the 'm.' 对于我尝试过的一切, 'm.' always ends up appearing at the END of the url, instead of at the start, like I want it too. 总是最终出现在URL的末尾,而不是像我想要的那样出现在开头。 I'm not sure if this is a Wordpress problem. 我不确定这是否是Wordpress问题。

If you have no www. 如果您没有www. prefix, you can do it with JavaScript this way: 前缀,您可以通过以下方式使用JavaScript:

href="javascript:window.location.href = window.location.href.replace('//', '//m.');void(0)"

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM