Mobile-Detect icon indicating copy to clipboard operation
Mobile-Detect copied to clipboard

Completely different website on Mobile Detect

Open umarmughal opened this issue 2 years ago • 4 comments

Hi Guys, it is possible to display a completely different website if detect mobile / tablet? let's say on desktop example.com and on mobile or tablet m.example.com hosted somewhere else even a non wordpress website ... possible?

umarmughal avatar Apr 27 '22 19:04 umarmughal

Depends on what system you're using.

Originally I did that with my company's website through PHP by just redirecting the browser to the mobile URL if Mobile-Detect gave me a "mobile/tablet positive" result.

$MobilDetect = new Mobile_Detect;
IF ($MobilDetect->isMobile()) {
    header("HTTP/1.1 307 Temporary Redirect");<!-- Can be header("HTTP/1.1 301 Moved Permanently"); if you want the browser to cache the redirect, but that kept causing my headaches over the years. -->
    header("Location: https://m.example.com/");
}

By now I realized that this approach was completely pointless, gave me WAY more problems to solve and so I just "collapsed" the two sites together and I'm using pure CSS to change the layout as needed.

If you also need different content you can just store the result of isMobile() in a variable and use that to switch between them in code.

Gaboris avatar Apr 27 '22 19:04 Gaboris

Thanks for your reply and explanation, my main website is purely WordPress but because of complex design (and more interactivity) i want a separate HTML version to display on Mobile / Tablets so how do i use this on WordPress .. any idea?

umarmughal avatar Apr 28 '22 00:04 umarmughal

The dedicated template for mobile is an old approach, you should design or choose a template to be adaptive to different devices width, and that is called to be responsive.

DrLightman avatar Apr 28 '22 06:04 DrLightman

Thanks for your reply and explanation, my main website is purely WordPress but because of complex design (and more interactivity) i want a separate HTML version to display on Mobile / Tablets so how do i use this on WordPress .. any idea?

Sadly no idea. I don't really like WP. IF they support adding in Mobile-Detect as it is then maybe they have options for adding in custom code as well?

The dedicated template for mobile is an old approach, you should design or choose a template to be adaptive to different devices width, and that is called to be responsive.

But exactly as Light said here. From personal experience you'd be better off with a total redesign that's properly responsive on all screen sizes instead of maintaining two different sites.

Gaboris avatar Apr 28 '22 09:04 Gaboris