I am trying to find a way to disable the twenty twelve stylesheet for anything in IE 8 or less. Is there a conditional code that I can put in my functions php file that will enable the default twentytwelve style sheet (and it's child themes child sheet) to be ignored in these particular browsers?

I want to start my IE only style sheet from a blank slate, and have only very very minimals styles applied.

Thanks in advance


Deregister twentytwelve-ie, which is registered (currently) in function.php on line 157.

function dereg_ie_styles_wpse_99631() {
add_action( 'wp_enqueue_scripts', 'dereg_ie_styles_wpse_99631', 1000);

That isn't just IE8 though. It is registered as less than or equal to IE 9.

If you want to remove all of the stylesheets for IE8 or less you are in for a bumpy ride. Conditional stylesheet loading for IE is handled by browser parsed conditional tags-- that is, tags read by IE but not by other browsers. The PHP on the server doesn't have to worry about what browser is reading the page.

To conditionally remove the primary stylesheet you are limited in options.

The first is user agent sniffing, and it isn't very reliable. You'd read $_SERVER['HTTP_USER_AGENT'] like wp_is_mobile does, check for IE User Agent strings and then conditionally remove the stylesheet with wp_deregister_script.

function dereg_ie_styles_wpse_99631() {
  if ( strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE') ) {
add_action( 'wp_enqueue_scripts', 'dereg_ie_styles_wpse_99631', 1000);

That is completely untested and, I think, ill-advised but there you are.

You might be able to cook something up with Javascript but I haven't even tried that. Javascript can probably do a better job at identifying IE but the rendering time delay would probably be noticeable.

  • Doing the above simply deregisters the IE only .css file. I need something that overrides the default style.css file if the version is IE 8 or less... – AirRon Happe May 16 '13 at 0:54
  • or perhaps the correct word is overwrite ? – AirRon Happe May 16 '13 at 0:55
  • @AirRonHappe : see the edit. – s_ha_dum May 16 '13 at 1:29
  • Thanks... this all seems too unreliable for me to want to deal with. Basically what I want to do is, what ever the easiest, and most efficient way to wipe styles clean for IE 8 and under. I am not concerned about my site looking good in IE and under, but I want the content to be accessible. So I am aiming for a styleless website for users of IE8 and under. – AirRon Happe May 16 '13 at 4:22
  • You can't "wipe styles clean" for any particular browser without the UA sniffing mentioned, which you admit seems unreliable. – s_ha_dum May 16 '13 at 4:41

You could also do this with just CSS / HTML!

In the HTML you can reuse the conditional HTML tags that the theme comes with like so. I've modified these for this example:

<!--[if lte IE 8]><html class="old-ie"><![endif]-->
<!--[if !(IE 6) | !(IE 7) | !(IE 8) ]><!--><html><!--<![endif]-->

Then in your CSS you could do something like so:

.old-ie * { display:none; }

With the same conditional tags I used in my HTML example you could actually call different CSS Link tags as well.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.