Add Conditional Styles in WordPress theme

A Standard Conditional IE comment looks like this
<!--[if lt IE 9]>
<link href="style.css" rel="stylesheet" type="text/css" />

You can easily code this in your header.php file and it will work fine but it’s not a good practice to do so. A better option is to use the functions and hooks provided by WordPress. You can add the following code to your functions.php file

add_action( 'wp_enqueue_scripts', 'enqueue_conditional_style' );
function enqueue_conditional_style() {

global $wp_styles;
$wp_styles->add(‘example_ie7-‘, ‘/themes/example/ie7-.css’);
$wp_styles->add_data(‘example_ie7-‘, ‘conditional’, ‘lte IE 7’);



Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s