php – Template_redirect based on if visiting from Firefox


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() {
        }, 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
theMap 1 month 2021-12-09T20:54:59-05:00 0 Answers 0 views 0

Leave an answer