I have looked around and can not find anything that fully works for my issue: I want to be able to set the home page template on the fly when a user is visiting from a mobile phone but not a tablet. I already have this check in place.

However I am able to change the whole theme on all pages when a visitor is on a phone but there does not seem to be a way to only change the template/theme on the home page.

Due to the only way I know for sure is checking is_front_page() which does not exist when you hook to change the theme. I also want to try to do this without redirecting to another page if possible.

  • 2
    Have you already tried something? How do you check for mobile users? Server-side or client-side? – Mateusz Hajdziony Jan 7 '13 at 17:07
  • Paste the code you have already for the check. – Brad Dalton Nov 28 '14 at 2:20

Or you can use another way, may be bit long but will give you full control how you want to drive your site/template.

Make responsive CSS. Call desktop styles in tablet view/resolution with media queries and for the smaller device, set styles as you want.

This will give you control in a way that you can have totally different layout in portrait and landscape view of a single device.


You could use template_include with wp_is_mobile

add_filter( 'template_include', 'mobile_front_page_template', 99 );

function mobile_front_page_template( $template ) {

    if ( wp_is_mobile() && is_front_page() ) {
        $new_template = locate_template( array( 'mobile-front-page-template.php' ) );
        if ( '' != $new_template ) {
            return $new_template ;

    return $template;

Then you could use another conditional tag to exclude tablets.

  • 1
    Just to note, wp_is_mobile() is a disgrace, unrealiable and should not be used outside the circus ring ;-) – Pieter Goosen Jun 4 '15 at 12:43
  • thanks for the feedback. Why do they keep it in core? – Brad Dalton Jun 4 '15 at 13:11
  • It is the same as query_posts, if the core developers removes it from core, they will break thousands of sites. Think they will be skinned alive ;-) – Pieter Goosen Jun 4 '15 at 13:21
  • Ok, so whats the best option for mobile conditionals? – Brad Dalton Jun 4 '15 at 13:48
  • 4
    To be honest, there is no reliable way or quick way to do this unfortunately. Client side applications should never be trusted. wp_is_mobile() can be used if you wish, but you must know it will fail in some instances. It is up to you if can live with that. Responsive design, or creating two sites and let the user choose between desktop and mobile site is about the best options – Pieter Goosen Jun 4 '15 at 14:14

You could check for a mobile device using wp_is_mobile() and then include the right template part with get_template_part().

Header and footer can be styled quickly with a couple of css media queries.

  • 6
    wp_is_mobile will not distinguish between phones and tablets. It is a very simple function. – s_ha_dum Jan 7 '13 at 18:45


mobble provides mobile related conditional functions for your site. e.g. is_iphone(), is_mobile() and is_tablet().

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.