-
AuthorPosts
-
November 28, 2021 at 10:04 am #1330727
Hello dear Kriesi team,
I would like to create two different start pages. Once a start page for mobile devices and a start page for PC and large screens. Is that possible with Enfold?
With best regards
SeverinNovember 28, 2021 at 7:25 pm #1330752Hey Severin,
There is not a built-in feature for this but you could try this function. Try adding this code to the end of your functions.php file in Appearance ▸ Editor:function custom_mobile_homepage() { ?> <script> if (window.location.pathname == '/' && jQuery(window).width() <= 480) { window.location = "/mobile-homepage/"; } </script> <?php } add_action( 'wp_head', 'custom_mobile_homepage', 10 );
adjust the
/mobile-homepage/
to your new page.Best regards,
MikeNovember 29, 2021 at 10:33 pm #1330894Hello Mike,
Unfortunately it does not work.
Take a look yourself.
But then please set it to inactive again.
Thank you very much for your help.
Best regards, SeverinNovember 30, 2021 at 10:58 am #1330971Hi,
Thank you for the info.
You might be able to use the wp_is_mobile function to detect if the current device used is mobile and the wp_redirect function to redirect the users to a different page if the first condition is true.
// https://developer.wordpress.org/reference/functions/wp_is_mobile/
// https://developer.wordpress.org/reference/functions/wp_redirect/Best regards,
IsmaelNovember 30, 2021 at 4:54 pm #1331027can you try mikes post with that if clause
function landingpage_for_mobile() { if(wp_is_mobile()){ ?> <script> if (window.location.pathname == '/' ) { window.location = "/mobile-home/"; } </script> <?php } } add_action( 'wp_head', 'landingpage_for_mobile', 10 );
or:
function redirect_mobile_devices() { if ( wp_is_mobile() && is_front_page() ) { wp_safe_redirect( get_site_url(). '/mobile-home', 301 ); exit; } } add_action( 'wp', 'redirect_mobile_devices' );
December 1, 2021 at 4:47 am #1331075Hi,
Thanks for the login, the reason this didn’t work was because you are forcing jQuery to load in the footer so you were getting an error, to correct I removed the jQuery part of the script and now it works. Although it is disabled as you requested.
This is the new script.function custom_mobile_homepage() { ?> <script> const mediaQuery = window.matchMedia('(max-width: 480px)'); if (window.location.pathname == '/' && mediaQuery) { window.location = "/startseite-mobil/"; } </script> <?php } add_action( 'wp_head', 'custom_mobile_homepage', 10 );
Best regards,
MikeDecember 20, 2021 at 9:08 am #1333499Hi Mike,
thank you, but unfortunately it doesn’t work completely yet. The diversion works. But when I activate the function, it is also active for the computer view. Best regards, SeverinDecember 20, 2021 at 11:28 am #1333515Hi,
Did you try @Guenni007’s suggestion above? The code should redirect the user to the specified page (mobile-home) on mobile devices.
function redirect_mobile_devices() { if ( wp_is_mobile() && is_front_page() ) { wp_safe_redirect( get_site_url(). '/mobile-home', 301 ); exit; } } add_action( 'wp', 'redirect_mobile_devices' );
Best regards,
Ismael -
AuthorPosts
- You must be logged in to reply to this topic.