Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have a bunch of code that I tend to put into the header.php of every site I do which are specific to Internet Explorer.

I was wondering if there was a way to insert code into a 'standard' header.php.

Yes, I can simply modify the header. But the idea is to make this a plugin which is generic.

Specifically, I'd like to create a plugin to echo the following in the header immediately after the default stylesheet:

<!--[if IE]>
  <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/ie.css" type="text/css" />
<![endif]-->
share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

One way to do it is using the wp_head action:

function wpse85495_header() {
?>
<!--[if IE]>
  <link rel="stylesheet" href="<?php bloginfo('stylesheet_directory'); ?>/ie.css" type="text/css" />
<![endif]-->
<?php
}
add_action('wp_head','wpse85495_header');

but I think the prefered way is using wp_enqueue_style() in a conditional way as described here:

http://core.trac.wordpress.org/ticket/10618#comment:6

function wpa85495_enqueue_style(){
    wp_enqueue_style('my-style', WP_PLUGIN_URL . '/my-plugin/style.css', false );
    global $wp_styles;
    $wp_styles->add_data( 'my-style', 'conditional', 'IE' );
}

add_action( 'wp_enqueue_scripts', 'wpa85495_enqueue_style' );
share|improve this answer
    
Fabulous! I -knew- there had to be a way that worked within the WP core. Big Cheers! Opens up a number of other possibilities. –  jchwebdev Feb 12 '13 at 20:36
add comment

You want wp_enqueue_style(). It's considered best practice and all around more elegant than hooking into the wp_head.

http://codex.wordpress.org/Function_Reference/wp_enqueue_style

share|improve this answer
1  
What would one do about the IE checking using wp_enqueue_style? –  brasofilo Feb 12 '13 at 3:50
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.