WordPress.org

Make WordPress Core

#21162 closed enhancement (duplicate)

Add !IE conditional comment on $wp_styles->add_data

Reported by: Umbercode Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: General Keywords:
Focuses: Cc:

Description

There is no way to use $wp_styles->add_data("css_ie", "conditional", "!IE"); and target non-IE browsers.
There are use cases for this for example:

<!--[if (gt IE 8) | (IEMobile)]><!-->
<link rel='stylesheet' href='<?php bloginfo("template_url"); ?>/css/style.css'><!--<![endif]-->

<!--[if (lt IE 9) & (!IEMobile)]>
<link rel='stylesheet' href='<?php bloginfo("template_url"); ?>/css/ie.css'><![endif]-->

I do not know how to attach a patch or diff file but I changed the code in class.wp-styles.php between lines 69 and 75 to:

if ( isset($obj->extra['conditional']) && $obj->extra['conditional'] ) {
	if (strpos(strtoupper($obj->extra['conditional']), "!IE")) {
	   $tag .= "<!--[if {$obj->extra['conditional']}]><!-->\n";
	   $end_cond = "<!--<![endif]-->\n";
	}
	else {
	   $tag .= "<!--[if {$obj->extra['conditional']}]>\n";
	   $end_cond = "<![endif]-->\n";
	}

which seems to work.

Change History (2)

comment:1 Umbercode22 months ago

It should probably be:

if (strpos(strtoupper($obj->extra['conditional']), "(!IE)")) {

in order to distinguish between !IEMobile and !IE

I guess there could be a more elegant solution?

comment:2 ocean9022 months ago

  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed
  • Version 3.4 deleted
Note: See TracTickets for help on using tickets.