[theme-reviewers] Using wp_enqueue_style() With IE Conditionals

Sayontan Sinha sayontan at gmail.com
Thu Apr 21 19:36:23 UTC 2011


There are some issues with the "conditional" enqueue method above - it
cannot handle negative conditions properly. Consider, for example, including
a CSS for rounded corners if the browser is not IE. See this ticket:
http://core.trac.wordpress.org/ticket/16118. There is a patch provided in
this thread, but I haven't checked if the patch is a part of the core yet.

I believe you can use an alternative approach making use of the
"style_loader_tag":

// First add a filter to style_loader_tag:
add_filter('style_loader_tag', 'filter_rounded_corners_css', 10, 2);

// Define the filter function:
function filter_rounded_corners_css($css_html_tag, $handle) {
    // If the stylesheet handle is "rounded" only then this style will take
effect
    if ($handle == 'rounded') {
        return "<!--[if !IE]>-->".$css_html_tag."<!--<![endif]-->\n";
    }
    return $css_html_tag;
}

// The handle is "rounded", which causes the inclusion of the
rounded-corners.css file.
wp_register_style('rounded',
get_template_directory_uri().'/rounded-corners.css');


Sayontan.

On Thu, Apr 21, 2011 at 11:50 AM, Edward Caissie
<edward.caissie at gmail.com>wrote:

> I agree with "recommended" for adding additional stylesheets via
> wp_enqueue_style() immediately and pushing it to required with 3.2; which
> seems will not be all that far off.
>
> I would also think that example, or similar ones, should be linked to so
> authors have something to work from if/when they adapt this "new" method.
>
>
> Cais.
>
>
> On Thu, Apr 21, 2011 at 2:39 PM, Chip Bennett <chip at chipbennett.net>wrote:
>
>> I agree - but we rarely take something from a non-suggestion to *required*
>> in one step, unless a critical need exists.
>>
>> The general path is to make something *recommended*, fit-test it for a
>> while, and then bump it up to *required*.
>>
>> Chip
>>
>>
>> On Fri, Apr 22, 2011 at 1:27 PM, Justin Tadlock <justin at justintadlock.com
>> > wrote:
>>
>>>  This should be the *required* way.  Additional stylesheets should always
>>> be added with wp_enqueue_style().  This is what I've been putting in my
>>> reviews, even for conditional stylesheets.
>>>
>>>
>>> On 4/21/2011 1:22 PM, Chip Bennett wrote:
>>>
>>> I just found this:
>>>
>>> http://iamzed.com/2010/01/07/using-wordpress-wp_enqueue_style-with-conditionals/
>>>
>>>  wp_enqueue_style(
>>>    'ie7-style',
>>>    get_template_directory_uri() . '/ie7.css'
>>> );
>>> global <http://www.php.net/global> $wp_styles;
>>> $wp_styles->add_data( 'ie7-style', 'conditional', 'lte IE 7′);
>>>
>>>
>>>  This might move into the Guidelines, as *Recommended* implementation of
>>> enqueueing IE-conditional stylesheets. Thoughts?
>>>
>>>  Chip
>>>
>>>
>>> _______________________________________________
>>> theme-reviewers mailing listtheme-reviewers at lists.wordpress.orghttp://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>
>>>
>>> _______________________________________________
>>> theme-reviewers mailing list
>>> theme-reviewers at lists.wordpress.org
>>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>>
>>>
>>
>> _______________________________________________
>> theme-reviewers mailing list
>> theme-reviewers at lists.wordpress.org
>> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>>
>>
>
> _______________________________________________
> theme-reviewers mailing list
> theme-reviewers at lists.wordpress.org
> http://lists.wordpress.org/mailman/listinfo/theme-reviewers
>
>


-- 
Sayontan Sinha
http://mynethome.net | http://mynethome.net/blog
--
Beating Australia in Cricket is like killing a celebrity. The death gets
more coverage than the crime.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.wordpress.org/pipermail/theme-reviewers/attachments/20110421/36724806/attachment-0001.htm>


More information about the theme-reviewers mailing list