- This topic has 13 replies, 4 voices, and was last updated 4 years, 2 months ago by Leo.
-
AuthorPosts
-
April 10, 2018 at 4:33 am #546174Alberto
Hello.
I’d like to show a different homepage if I’m visiting the website from a mobile, i.e., if I go to my website from a desktop computer (or a tablet) I visit homepage1 and if I go to my website from a mobile I visit homepage2.
Could you tell me what’s the best approach to achieve this?Thanks in advance.
April 10, 2018 at 9:06 am #546460TomLead DeveloperLead DeveloperI believe you would need to use some sort of mobile app.
For example, Jetpack has a “mobile theme” you can activate.
You can also try a plugin like this: https://en-ca.wordpress.org/plugins/wptouch/
April 10, 2018 at 10:07 am #546532AlbertoThank you, Tom.
I?ll give it a chance.April 10, 2018 at 5:16 pm #546820TomLead DeveloperLead DeveloperYou’re welcome π
April 18, 2018 at 4:34 am #553627AlbertoHello Tom!
I was trying with WP Touch plugin but it’s definitely not what I’m looking for. I only want to redirect my homepage to a different one on my website if I’m using a mobile device, so I’m trying with this code in the wp_head GP Hooks<?php if ( wp_is_mobile() AND is_front_page() ) { wp_redirect( 'https://beta.zeine.es/contacto-movil', 301 ); exit; } ?>
But I am getting this warning and nothing more is showed:
Warning: Cannot modify header information – headers already sent by (output started at /my-path/wp-includes/class.wp-styles.php:225) in /my-path/wp-includes/pluggable.php on line 1216Am I using correctly the code above?
I’ve also tried it on my functions.php using the add_action(‘init’,’my_function’) hook
What’s the issue here?Thanks in advance.
April 18, 2018 at 8:53 am #553888TomLead DeveloperLead DeveloperInteresting, I wasn’t aware of
wp_is_mobile()
.Can you check your
error_log
file for a more specific error possibly?April 18, 2018 at 10:37 am #554010AlbertoHi Tom!
Thanks for replying.
I’m afraid I can’t access the error log file. I think it’s in a directory that I don’t have permission to access. I’m going to ask if is it possible to get access.
Is there any other way I could help?Regards
April 18, 2018 at 12:03 pm #554057AlbertoHello
I’ve managed to access error.log but it does not show any particular errors…You can see the warning message if you try https://beta.zeine.es from a mobile device.
April 18, 2018 at 8:59 pm #554306TomLead DeveloperLead DeveloperInstead of adding it in wp_head, try adding this function:
add_action( 'wp', 'tu_redirect_mobile' ); function tu_redirect_mobile() { if ( wp_is_mobile() AND is_front_page() ) { wp_redirect( 'https://beta.zeine.es/contacto-movil', 301 ); exit; } }
Adding PHP: https://docs.generatepress.com/article/adding-php/
April 19, 2018 at 4:27 am #554575AlbertoHi Tom
It works!
Thanks so much!April 19, 2018 at 7:30 am #554717TomLead DeveloperLead DeveloperAwesome, Glad I could help π
February 2, 2020 at 8:15 am #1152172manaadiarHi Tom unfortunately the above code is not working for me.. I am running GP Premium.. Can you pls advise..??
February 2, 2020 at 8:16 am #1152173manaadiarPls ignore.. I used the theme options and it is fine now.. Sorry..
February 2, 2020 at 9:54 am #1152240LeoStaffCustomer SupportGlad you’ve figured out π
-
AuthorPosts
- You must be logged in to reply to this topic.