options - Different Front page for Mobile

admin2025-06-03  4

I want to make a different front-page and show it to the mobile user, instead of the one used on desktop.

In detail, right now we have set our site to show desktop-front-page to user, when he lands on www.domain. Now, I want to make a different front-page (mobile-front-page) which can be served to the user coming from mobile. Is that possible? Any ideas?

PS. I looked into wp_is_mobile() but that seems to send mobile user to a URL you specify. What I actually need is that user should land (and remain) on www.domain, but instead of the desktop-front-page, the mobile-front-page should be served.

I want to make a different front-page and show it to the mobile user, instead of the one used on desktop.

In detail, right now we have set our site to show desktop-front-page to user, when he lands on www.domain. Now, I want to make a different front-page (mobile-front-page) which can be served to the user coming from mobile. Is that possible? Any ideas?

PS. I looked into wp_is_mobile() but that seems to send mobile user to a URL you specify. What I actually need is that user should land (and remain) on www.domain, but instead of the desktop-front-page, the mobile-front-page should be served.

Share Improve this question asked Oct 15, 2014 at 8:39 vajrasarvajrasar 1693 silver badges19 bronze badges
Add a comment  | 

3 Answers 3

Reset to default 2

Switching the actual template file could work in the same way as above using get_template_part().

For example...

<?php
if ( wp_is_mobile() ) { // If it is a mobile device

get_template_part( 'mobile-front', 'page' );

} else { // If it is not a mobile device

get_template_part( 'desktop-front', 'page' );

} // end wp_is_mobile()

To take this a step further...

You could add a filter on template_include to load the specific template file using wp_is_mobile() to determine which template file to load.

The Codex info for template_include.

I believe you're on the right track with wp_is_mobile().

Have you tried creating just one front-page.php and adding an if / else statement to alter display between desktop and mobile?

Something like:

 <?php
if ( wp_is_mobile() ) { // If it is a mobile device

get_header( 'mobile' );
// Display some other stuff here
get_footer( 'mobile' );

} else { // If it is not a mobile device

get_header();
// Display some other stuff here
get_footer();

} // end wp_is_mobile()

I know I might be off as this is an old question but I have found this answer here and it works, it simply redirects the main page to the mobile home page using this script in the home page text editor where /mobile is the link you want to redirect to. I have tried it and it works you can check it on medicalfa.

<script>
 if (document.documentElement.clientWidth <760) {
   window.location = "/mobile";
 }
 </script>
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1748916854a314794.html

最新回复(0)