Redirect Page to Mobile Version in Wordpress

我们两清 提交于 2019-12-31 07:28:07

问题


I would like to setup mobile redirection using the htaccess in my Wordpress website.

I have a mobile site (mobile.domain.com) and regular site (domain.com) The permalinks will be the same for each site e.g. domain.com/page-one/ and mobile.domain.com/page-one/ so it seems like it should be fairly easy to redirect to the same page in the mobile site.

I've tried looking online and cant find what I need, can anyone help with this? I would be happy just using a plugin if one already exists.


回答1:


I know this is an old post, but after figuring this out I think the solution I used is worth mentioning here.

Everyone knows that a simple Javascript redirect will work great, but what if you want the user to end up on a page that has the exact same path name? If you have this redirect, then "example.com/contact" will be redirected to "mobile.example.com" - notice how this is not the mobile version of the contact page.

The solution is to have a Javascript snippet in the main header that will tell each page to keep its same pathname when redirected, such as "/contact". The one caveat is that each mobile page must be named the same as the desktop version - /whatever and /whatever.

<script type="text/javascript">
    <!--
    if (screen.width <= 800) {
        document.location = "https://mobile.example.com" + window.location.pathname;
    }
</script>



回答2:


you could do the following in javascript:

<script language="JavaScript" type="text/javascript">
if ((screen.width>=1024) && (screen.height>=768))
{
 window.location.replace('example.html');
}

</script>

This would need to go in your header.php




回答3:


Check this website http://detectmobilebrowsers.com/ for php or javascript code. You can use PHP or Javascript, that you have to paste within header.php




回答4:


Solution:

Download and install plugin : CSS & Javascript Toolbox

  • (make sure to always backup before downloading and installing plugins)

Add this javascript to the page you want to redirect from.

<script type="text/javascript">  
<!--  

if (screen.width <= 600)  

{   
   window.location="http://www.yourmobilesite.com";  
}  
//-->  
</script>


来源:https://stackoverflow.com/questions/17925811/redirect-page-to-mobile-version-in-wordpress

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!