$conf, $runtime; function_exists('chdir') AND chdir(APP_PATH); $r = 'mysql' == $conf['cache']['type'] ? website_set('runtime', $runtime) : cache_set('runtime', $runtime); } function runtime_truncate() { global $conf; 'mysql' == $conf['cache']['type'] ? website_set('runtime', '') : cache_delete('runtime'); } register_shutdown_function('runtime_save'); ?>options - Different Front page for Mobile|Programmer puzzle solving
最新消息:Welcome to the puzzle paradise for programmers! Here, a well-designed puzzle awaits you. From code logic puzzles to algorithmic challenges, each level is closely centered on the programmer's expertise and skills. Whether you're a novice programmer or an experienced tech guru, you'll find your own challenges on this site. In the process of solving puzzles, you can not only exercise your thinking skills, but also deepen your understanding and application of programming knowledge. Come to start this puzzle journey full of wisdom and challenges, with many programmers to compete with each other and show your programming wisdom! Translated with DeepL.com (free version)

options - Different Front page for Mobile

matteradmin8PV0评论

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>

Articles related to this article

Post a comment

comment list (0)

  1. No comments so far