php – Template_redirect based on if visiting from Firefox

Question

So below I will explain all the details that I’m attempting to do and kind of go into detail on the setup:


Here is what I’m attempting to do:
If I make a request in the template_rewrite to /internet-explorer-11, intercept the request, don’t load the generic page template but load in the new page-internet-explorer-11 template and show a generic die().

Once we hook into before authentication add_action('init') (works), and you are entering the site of any url, if using Firefox, redirect to the internet-explorer-11 page with the internet-explorer-11 page template.

I don’t know if I wrote the code piece correctly, so I’m open to all the help!


I see my page template with my created page:
enter image description here

Here is my code attempt:

add_action('init', function() {
    $firefox = strpos($_SERVER["HTTP_USER_AGENT"], 'Firefox');
    if ($firefox) {
        add_action('template_redirect', function() {
            wp_redirect(home_url('/internet-explorer-11/'));
            exit();
        }, 10);
    }
}, 999, 1);

How it currently works:

  • When visiting the website from any url, it will redirect to the internet-explorer-11 page, but I get the following message:
    enter image description here
0
theMap 1 year 2021-12-09T20:54:59-05:00 0 Answers 0 views 0

Leave an answer

Browse
Browse