Sometimes you may want to add browser specific stylesheet in WordPress. For example, you want to load a stylesheet when a user visits your site using Internet Explorer ( I know you hate IE
).
You need to detect the browser. WordPress is very handy for detecting browsers using global variables.
To detect if the user is on Internet Explorer, use $is_IE global variable. You may use it like bellow:
1 2 3 4 | global $is_IE;
if( $is_IE ) {
// do something for IE
} |
You may add the condition just before the link tag in header.php file to add a stylesheet in your theme. Like bellow:
1 2 3 | If( $is_IE ) {
echo ‘<link rel=”stylesheet” media=”all” href=”http://path-to-style.css”/>’;
} |
But adding the stylesheet in header.php is not ideal. If you’re developing a theme for personal use, then this is okay but if you are developing the theme for WordPress community, you have to think bit more!
