• I have a simple bit of PHP code in the head section of my pages to load an Internet Explorer-specific stylesheet if necessary:

    <?php
    	$useragent = $_SERVER['HTTP_USER_AGENT'];
    	if (stristr ($useragent, 'MSIE')) {
    	echo ('<link rel=stylesheet href="https://www.domain.org/nwwstyleIE.css" type="text/css">'); } ?>

    Since most readers use MSIE, pages tend to be wp-cached <i>with</i> the MSIE stylesheet. (Ignoring for now the super-cached pages for logged-in users, most of whom use Firefox thus creating the opposite issue.)

    The result is that non-MSIE readers get a messed-up layout. Or MSIE readers get a messed-up layout if the page was first viewed by a Firefox or Safari user.

    How can I still dynamically supply the MSIE stylesheet in the cached file as needed? Javascript (which I unfortunately don’t know at all well)?

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter ericr23

    (@ericr23)

    I just learned about Microsoft’s conditional comments. Would it work to replace the php code (see original post) with the following?

    <!--[if IE]>
    <link rel=stylesheet href="https://www.domain.org/nwwstyleIE.css" type="text/css">
    <![endif]-->

    eric – that should work. Since the PHP doesn’t execute on cached pages you have to rely on Javascript or some other method.

    Moderator Samuel Wood (Otto)

    (@otto42)

    www.remarpro.com Admin

    The conditional comments are definitely the recommended way to have IE-specific rules.

    Alternately, a trick I use for IE specific fixes is to add // infront of any IE specific rules. Like so:
    .whatever {
    some-setting:rule;
    //some-setting:other-rule;
    }

    IE will use the second rule because it doesn’t treat the // as comment markers. Every other browser does think it’s a comment and ignores it.

    Thread Starter ericr23

    (@ericr23)

    Thanks, all. That’s a neat trick for stylesheets, Otto. I’ve had the IE conditional comment in place instead of the PHP code for a couple days now, and that appears to have worked.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: WP Super Cache] Browser-specific stylesheets in wp-cache pages?’ is closed to new replies.