0

I am looking for a simple clean solution when someone visits my homepage with a mobile device. Should I use something like Mobile Detect? I've seen many plugins with lots of downvotes or crashing.

Is it otherwise possible to only add a javascript thingie on the homepage only?

if ('ontouchstart' in window)  window.location = 'http://someurl.com/single/page';
  • Why would you want to redirect the user to another page? He wants to see what he clicked on in search results or wherever... – flomei May 28 '15 at 22:48
  • Well, when you have parallax scrolling containg sections (actually pages), you want better performance on mobile devices. So the homepage containing all pages redirects to the top page – poashoas May 29 '15 at 8:18
0

You could use wp_is_mobile with wp_redirect

if ( wp_is_mobile() AND is_front_page() ) {
    wp_redirect( $location, $status );
exit;
}

You can add the js directly to a front-page.php or home.php file or enqueue it directly from either file.

Example:

add_action('wp_enqueue_scripts', 'load_script');
function load_script(){
    wp_enqueue_script( 'script-handle', get_stylesheet_directory_uri() . '/js/your-script.js', array( 'jquery' ) );
}
0

I hope it will help you to detect

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()) {   alert("This is a Mobile Device");}

You can read more about it here. http://jstricks.com/detect-mobile-devices-javascript-jquery/

0

If you're using wordpress, give this plugin a try - http://www.ultimate-wordpress-mobile-redirect.com

With this plugin you can set a unique redirect URL for every page and post of your website.

-1

Javascript Thingie!! You should have tried Mobile Detect first. That should suffice your requirement. If you need more help using the plugin, consider posting on their support forum on WP repo.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.