Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set a different Static homepage for Mobile version? (WordPress)

Tags:

wordpress

I would like to have a different static homepage for my mobile version of my website. It is not really an extra mobile version but it is responsive.

I have a Fullscreen Image slider right now set as the static homepage. This scales to the screensize, due to the responsive build of the website, but it does not look very nice on a mobile device, such as an iPhone. So I have this other homepage template which I would like to use when the website is being viewed on a mobile device.

Can this be done by any plugins or should it be done by coding? I don't want to use a theme switcher or something like that, I just want to have a different static page set for mobile devices.

How can I do this?

like image 883
Ronald Wildschut Avatar asked Apr 23 '13 09:04

Ronald Wildschut


People also ask

How do I edit a mobile version of WordPress site without affecting it's desktop view?

Start by selecting the column you want to customize and then on the left side panel click on the Advanced tab. From there find the Responsive dropdown to find the options to enable/disable the visibility of the column or element on that size. Customize your option, hit save changes and you're good to go!

How do I change my mobile theme on WordPress?

Go to the plugins sections in WordPress. Press the “Add New” button at top of page. Type the plugin name “Theme Switch in Mobile and Desktop” Finally, install and activate the plugin.


2 Answers

You could use wp_is_mobile to check for mobile, and hook into template_redirect to load a different template if mobile is detected:

function so16165211_mobile_home_redirect(){
    if( wp_is_mobile() && is_front_page() ){
        include( get_template_directory() . '/home-mobile.php' );
        exit;
    }
}
add_action( 'template_redirect', 'so16165211_mobile_home_redirect' );
like image 141
diggy Avatar answered Sep 22 '22 10:09

diggy


I would include Mobile-Detect into the theme in its own folder and add this code in the beginning of header.php:

if( is_front_page() ){

    include_once('mobile-detect/Mobile_Detect.php');
    $detect = new Mobile_Detect(); 

    if ( $detect->isMobile() || $detect->isTablet() ) {
        $redirect_url = 'http://example.com/mobile_home';
        header('Location: ' . $redirect_url ); // Redirect the user
    }
}

You could customize this solution to work just as you want. I have used this for several projects for similiar solutions.

like image 26
MrZiggyStardust Avatar answered Sep 22 '22 10:09

MrZiggyStardust