[Resolved] Different homepage for mobile

Home Forums Support [Resolved] Different homepage for mobile

Home Forums Support Different homepage for mobile

Viewing 14 posts - 1 through 14 (of 14 total)
  • Author
    Posts
  • #546174
    Alberto

    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.

    #546460
    Tom
    Lead Developer
    Lead Developer

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

    #546532
    Alberto

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

    #546820
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #553627
    Alberto

    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.

    #553888
    Tom
    Lead Developer
    Lead Developer

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

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

    #554010
    Alberto

    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

    #554057
    Alberto

    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.

    #554306
    Tom
    Lead Developer
    Lead Developer

    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/

    #554575
    Alberto

    Hi Tom
    It works!
    Thanks so much!

    #554717
    Tom
    Lead Developer
    Lead Developer

    Awesome, Glad I could help πŸ™‚

    #1152172
    manaadiar

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

    #1152173
    manaadiar

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

    #1152240
    Leo
    Staff
    Customer Support

    Glad you’ve figured out πŸ™‚

Viewing 14 posts - 1 through 14 (of 14 total)
  • You must be logged in to reply to this topic.