0

I have a WordPress site going, but the theme I am using (and wish to keep using for now) does not support Internet Explorer in any version as far as I can see.

I am really not looking for people telling me that it is a bad idea, I already know that. It is just for the short term that I need something to tell IE users to go to Edge, Chrome or Firefox (or any other browser I believe)

I did not realize when I bought the theme, that it does not what so ever support IE, and that sucks but I cant do much about it right now. The website is absolutely broken in every way in IE, so just to not get a bad look for the company, I am looking to temporarily block IE users from even seeing the website.

How can I make WordPress check for IE and maybe give them a popup message or error window asking them to go to another browser.

I found this post, which is asking pretty much the same as me, but I could not get the answers to work.

https://www.quora.com/Is-there-a-way-to-block-Internet-Explorer-from-my-website-using-HTML-If-so-is-there-a-way-to-modify-that-code-for-other-browsers

Thank you a lot in advance!

Update: I have tried to use JS code to spoof the browsers, without any luck.

RolandASc
  • 3,863
  • 1
  • 11
  • 30
  • 1
    Use JS to browser detect - it's not perfect and can be spoofed, but the IE users you care about probably aren't try to spoof their browser. https://stackoverflow.com/questions/9847580/how-to-detect-safari-chrome-ie-firefox-and-opera-browser – disinfor Mar 22 '19 at 15:03
  • I cant seem to get this to work. I have the ability to add more JS to my website, but it does not seem to work. Could you make a code example that i can put into the "Additional JS" field? – Martin Skovrup Mar 22 '19 at 15:38
  • Edit your question to include what you tried to add to the JS field. Are you getting an error message? – disinfor Mar 22 '19 at 15:58
  • You can check `$_SERVER['HTTP_USER_AGENT']` in your template files to get the users browser. If the user is using IE you can redirect them to a page with the message you want to show. http://php.net/manual/en/reserved.variables.server.php – Azer Mar 22 '19 at 16:17
  • Thank you alot for the answers. If i change anything in the template files, would they not get overwritten when i update? Also, i am not very familia with PHP, especially not integrated with wordpress. Do you perhaps have an example, or a snippet from somewhere so i could see it? – Martin Skovrup Mar 22 '19 at 19:15
  • with regard to the 'spoofing': usually this means setting things up so the browser lies to the server about what kind of browser it is. That's not something you would do here, unless, say, you wanted to test the servers reaction to IE, but for some reason couldn't run it yourself. Perhaps you meant something else? Anyway, details on precisely what didn't work, including the code you used, would help. That said, doing it server side might be easier, particularly if you have little javascript experience. – Loren Rosen Mar 22 '19 at 19:17
  • Also, it may be a distinction not worth making, but IE 11 is much likely to work okay than, say IE 7. – Loren Rosen Mar 22 '19 at 19:19
  • Hello again guys, my bad. IE 11 does not work and IE7 doesnt either. IE is just completely messed up, so i have to change it at some point anyway, i would just like people not to see the messed up site for now. I do have some coding experience but not JavaScript in Wordpress. In Wordpress i have the ability to add "Additional JS" I believe it just adds it to another ".js" file. Non of the code i have found has done the job so far. I am hoping to just get/find some snippet of code that checks the browser, and if it's IE, then redirects the user to another page. – Martin Skovrup Mar 24 '19 at 08:42

1 Answers1

0

I have WordPress and this is what I do to block explorer. just insert this in header.php below the head tag.

<?php
    if (preg_match('~MSIE|Internet Explorer~i', $_SERVER['HTTP_USER_AGENT']) || (strpos($_SERVER['HTTP_USER_AGENT'], 'Trident/7.0; rv:11.0') !== false)) 
    {
        echo '<body style = "display:none;"></body>';
        echo "<script type='text/javascript'>alert('Sorry, Internet Explorer is not supported in this webpage');</script>";
    }
?>

Now if you want the user to use the page but receive an error just say echo 'Sorry, Internet Explorer is not supported in this webpage';

Marcello B.
  • 4,177
  • 11
  • 45
  • 65