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]-->
The preferred way is to enqueue it, with the default/main stylesheet as the dependency.
Here’s a demo plugin, with the structure:
where the
my-ie-style.php
file is:This will generate the following within the
<head>
tag:where our custom IE stylesheet loads after the main stylesheet.
Hopefully you can adjust it to your needs.
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