WordPress.org

Support

Support » How-To and Troubleshooting » mobile redirect – warning cannot modify header info

mobile redirect – warning cannot modify header info

  • Hi…

    Trying to add a redirect to my wordpress site to my mobile website.
    I have a custom home page that I created. I added the following to the custom home page:

    <?php
    $agent = $_SERVER[‘HTTP_USER_AGENT’];
    if(preg_match(‘/iPhone|Android|Blackberry/i’, $agent)){
    header(“Location: http://www.google.com“);
    exit;
    }
    ?>

    But it results in this error:

    Warning: Cannot modify header information – headers already sent by (output started at …..

    Is there a different place I should be adding this code?

Viewing 2 replies - 1 through 2 (of 2 total)
  • If it’s a header redirect then it should be before any other code that sends output to the user. Try putting it at the top of your header.php file.

    Ok…I added it to the very top of my customhome.php file. Seems to work but it doesn’t seem to redirect for my older verizon flip phone? Do you think i’m missing something in the expression to target all phones?

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘mobile redirect – warning cannot modify header info’ is closed to new replies.