WordPress.org

Ready to get started?Download WordPress

Forums

mobile redirect - warning cannot modify header info (3 posts)

  1. iluvwrdpress
    Member
    Posted 3 years ago #

    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?

  2. DigitalSquid
    Member
    Posted 3 years ago #

    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.

  3. iluvwrdpress
    Member
    Posted 3 years ago #

    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?

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.