WordPress.org

Ready to get started?Download WordPress

Forums

PHP Browser Detection
[resolved] How to Redirect? (15 posts)

  1. DrEZStreat
    Member
    Posted 1 year ago #

    Hello

    I have one page on my website that I'd like to use this plugin on.

    On that page, I want it to detect if anyone is using IE8 or lower.

    If so, I want the page to redirect to a different page.

    Is this possible, and how do I do it? I'd LOVE someone's help.

    http://wordpress.org/extend/plugins/php-browser-detection/

  2. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    Yes this is possible. Try:

    if(is_ie() && get_browser_version() <= 8) {
       wp_redirect('http://www.example.com', 301);
       exit;
    }

    Change "http://www.example.com" to whatever URL / page you want IE8 and lower people to go to.

  3. DrEZStreat
    Member
    Posted 1 year ago #

    Heh thanks works perfect.

  4. devrap
    Member
    Posted 1 year ago #

    Hi there. I'd actually like to do this exact same redirect for our entire site, and am unsure where to add this code to my theme?

    I've tried it both in the <head> tag of my theme's header.php file, and also in functions.php. But with both attempts, when testing in IE 8, nothing happened.

    Can you tell me where it's best to put this code to apply to all site pages (going to one redirect)?

    Many thanks.

  5. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    You should probably put this code at the very top of your header.php file, before anything else, even the <HTML> tag:

    <?php
    // redirect IE8 and lower visitors
    if(is_ie() && get_browser_version() <= 8) {
       wp_redirect('http://www.example.com', 301);
       exit;
    }
    ?>
  6. devrap
    Member
    Posted 1 year ago #

    Thanks so much for the quick response!

    I have added this as the first line to my theme's header.php file, and it is not redirecting when I test on IE8 (any/all pages in http://bigmoves.org/staging/ ).

    I also tried attaching it to routine functions in functions.php, and also giving it its own unique function name and calling that in header.php. Nothing seems to make a redirect work here... this is a single site install.

    (And yep, PHP Browser Detection is definitely installed and activated.)

    Because it's a responsive site, there is an html5 detection script in place looking for older than IE9 so as to run html5shiv, do you think that is interfering?

    <!--[if lt IE 9]><script src="https://html5shiv.googlecode.com/svn/trunk/html5.js"></script><![endif]-->

    Many thanks again.

  7. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    If you want to send me a temporary admin login for the site I can check it out (info AT mindsharestudios DOT com).

  8. devrap
    Member
    Posted 1 year ago #

    That's generous of you, if you have a minute. Just sent the info. Thanks!

  9. slshaw115
    Member
    Posted 1 year ago #

    I used the exact redirect code that you posted and it technically works but it takes forever to load for some reason. I am using a child them and have it in my modified header file within my child theme. When I add it to the parent theme header file the redirect doesn't work at all. If i set it to an external page like google.com or something it works fine but when I link to a page within my site (what I'm trying to do) it is painfully slow. Any help would be appreciated.

    Cheers

  10. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    @slshaw115 You probably have created a redirect loop.

    You need to make sure wp_redirect doesn't get called on the page you are redirecting to, otherwise it will keep redirecting over and over until the server stops the loop.

  11. slshaw115
    Member
    Posted 1 year ago #

    That makes sense. I'm just not sure where to put it other than in the header.php file to avoid this issue.

  12. Mindshare Studios, Inc.
    Member
    Plugin Author

    Posted 1 year ago #

    You would need to add some sort of test to see if the person is already on the redirect page. Try something like this:

    if(is_ie() && get_browser_version() < 9 && !is_page('please-update-your-browser')) {
       wp_redirect('/please-update-your-browser/', 301);
       exit;
    }

    You would need to replace "please-update-your-browser" with the slug or name of the page your are redirecting to.

  13. slshaw115
    Member
    Posted 1 year ago #

    No luck. Not sure why because that appears to me like the proper way to do it. I'll have to keep messing with it. Thanks so much for your help.

    Cheers

  14. John
    Member
    Posted 10 months ago #

    Hello, I have been attempting to do exactly what the author of this post has been attempting to do, which is redirect just one of my WordPress pages for mobile users, however I have gotten stuck. This is the code I'm using so far:

    <?php
    if ( is_mobile() && get_the_ID(2766) ) {
    wp_redirect('http://www.lifebyjohn.com/mobile-schedule');
    exit;}
    ?>

    I tried adding the code in header.php, as well as using the Code Snippets plugin so that it would go in functions.php. Did I mess the code up by chance? Or am I putting the code in the wrong place? I'm a relative newbie so patience with me would be appreciated :-)

    Thanks!

  15. WPyogi
    Volunteer Moderator
    Posted 10 months ago #

    @John - this thread is 5 months old and already marked resolved. Please start your own thread if you need help with this plugin.

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic

Tags