Stylianos Michael
Stylianos Michael

Reputation: 35

Redirect users visiting mobile site from desktop

i created 2 different website, one for mobile and one for desktop using Wordpress! I used a plugin called equivalent mobile redirect in order to redirect mobile users to the mobile site when they visit the desktop one! Now i need to do this vice versa and i cannot seem to find a efficient way! Any ideas?

Upvotes: 0

Views: 2055

Answers (2)

Argus Duong
Argus Duong

Reputation: 2654

Take a look at this code if you don't want to use Javascript. You can use WordPress's detect mobile function to redirect if visitor is on desktop browser.

if(!wp_is_mobile()){
    // If not using mobile
    wp_redirect( "https://your_desktop_site.com");
    exit;
}

You can add this code to your theme's functions.php file and it will work.

Upvotes: 1

Chandra Kumar
Chandra Kumar

Reputation: 4205

You can check with javascript:

var isMobile = {
    Android: function() {
        return navigator.userAgent.match(/Android/i);
    },
    BlackBerry: function() {
        return navigator.userAgent.match(/BlackBerry/i);
    },
    iOS: function() {
        return navigator.userAgent.match(/iPhone|iPad|iPod/i);
    },
    Opera: function() {
        return navigator.userAgent.match(/Opera Mini/i);
    },
    Windows: function() {
        return navigator.userAgent.match(/IEMobile/i);
    },
    any: function() {
        return (isMobile.Android() || isMobile.BlackBerry() || isMobile.iOS() || isMobile.Opera() || isMobile.Windows());
    }
};

if(isMobile.any()){
    // Mobile!
} else {
    // Desktop
}

Upvotes: 2

Related Questions