Forums

Conditional CSS in function.php (5 posts)

  1. DeirdreBunny
    Member
    Posted 2 months ago #

    Hey everyone -

    I am having a wee issue with referencing a conditional style sheet for IE.

    I've named the stylesheet "ie6.css" and want to add it to function.php, but every code I have tried does not work.

    Here is an example of one of the options I had been trying:

    function ie6_css() { ?>
    <!--[if lt IE 6]>
    <link rel="stylesheet" type="text/css" href="<?php echo bloginfo('stylesheet_directory') ?>/ie6.css" />
    <![endif]-->
    <?php }

    I have placed ie6.css in the theme's root directory where the default css resides, and have changed some style info to test if it is actually being picked up by IE 6 and so far, have had no luck. I am fairly certain the issue is in the above code - and likely something I've messed up or neglected. I wasn't sure what to put after the function statement, so I put "ie6_css" - not sure if that's the main problem or not.

    Anyway, does anyone have an suggestions on which code to add to my function.php file to get IE to play nice? I really want to target all versions of IE prior to IE8 - the site seems fine in IE8, its just IE 6 & 7 that are the issues.

    Thank you!

    ~Deirdre

  2. esmi
    Member
    Posted 2 months ago #

    Why are you trying to add the conditional comment to functions.php? It belongs in header.php - after your calls to the default css file.

    http://quirm.net/2009/06/29/wordpress-conditional-comment-css/

  3. DeirdreBunny
    Member
    Posted 2 months ago #

    Because the theme my client installed does not call up the file in the usual way. Regardless, I tried using the standard code (and many variations thereof) in the header to pull up the style sheet, and it had no effect. So, while searching, I found some information about that theme and it was recommended to use function.php to call the CSS.

    I just logged i to update people in case they had a similar question - I have finally met with success. I was using <!--[if lt IE 6]> not realizing that "lt" meant versions *less* than 6, not 6 itself - which is why IE6 was not showing any change. I replaced the 6 with: <!--[if lt IE 8]> to target versions prior to IE8, and that did the trick.

    Thanks for the link, I will keep it around for future use.

  4. esmi
    Member
    Posted 2 months ago #

    FWIW, <!--[if lte IE 6]> = less than or equal to IE6.

  5. DeirdreBunny
    Member
    Posted 2 months ago #

    Thanks!

Reply

You must log in to post.

About this Topic