0

I am looking for a way from 3 days to load different homepage for mobile devices.But did not get any success.

1

This question is pretty vague but I'll give it a shot. A few options:

1) Check out WPtouch - http://www.wptouch.com/ - This plugin gives you the ability to override certain aspects of your primary theme with mobile friendly templates instead.

2) This is not ideal but you could use some basic Javascript to check the screen size of the current device and manually redirect any "mobile" screen sizes to a new page.

3) Finally, if #1 is overkill and #2 is too basic you'll need to go the custom code route. Specifically you need a device detection script or library. This will allow PHP to detect when you are on mobile vs. other devices. Once you know what kind of device you are dealing with you can code some logic into your theme that displays the desired template or content based on that device.

|improve this answer|||||
1

You could use the template_include action hook combined with the wp_is_mobile() function for this:

function wpse_maybe_load_mobile( $template ) {
    if ( is_front_page() && wp_is_mobile() ) {
        $new_template = locate_template( array( 'your-template-file.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;
       }
    }
    return $template;
}
add_action( 'template_include', 'wpse_maybe_load_mobile' );
|improve this answer|||||
  • Although this might be useful, it is however to note that wp_is_mobile() is very unreliable, so are any theme switcher which switch between devices and screen sizes ;-) – Pieter Goosen Oct 1 '15 at 5:53
0

You need to retrieve the client's user agent. In order to do to this, I usually use the library jenssegers/agent. First, require the library in your functions.php or add it to Composer if you use it. Then, you can now create instances of objects that get the client's user agent with :

  $agent = new Agent();
    if($agent->is_Mobile()) {
    //this code will be executed if the client send a user agent that's referenced as mobile
    }

I've used it on a number of projects, it's pretty reliable.

|improve this answer|||||

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.