Site logo

Archived topic

Different homepage for mobile

13 replies · Started by Alberto on April 10, 2018

Viewing posts 1–14 of 14

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.

Thank you, Tom.
I?ll give it a chance.

You're welcome :)

Hello 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 1216

Am 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.

Interesting, I wasn't aware of wp_is_mobile().

Can you check your error_log file for a more specific error possibly?

Hi 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

Hello
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.

Instead 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/

Hi Tom
It works!
Thanks so much!

Awesome, Glad I could help :)

Hi Tom unfortunately the above code is not working for me.. I am running GP Premium.. Can you pls advise..??

Pls ignore.. I used the theme options and it is fine now.. Sorry..

Glad you've figured out :)

This archived topic is closed to new replies.