Title: simple: Browser detection?
Last modified: August 18, 2016

---

# simple: Browser detection?

 *  [davitz](https://wordpress.org/support/users/davitz/)
 * (@davitz)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/)
 * Hia!
 * Still being a total newbie, I’m having troubles to properly detect a browser.(
   I need this to serve MSIE a different stylesheet, and some script-stuff).
 * I managed to successfully throw a copy of the //Simple browser detection from
   the file vars.php into the header.php, but of course I’d prefer to use the “original”(
   already generated) variable that comes out of the vars.php.
 * What string would I insert into the headers.php? (I tried stuff like
 * <?php
    if (($is_winIE) || ($is_macIE) { ?> <link rel=”stylesheet” href=”<?php
   bloginfo(‘stylesheet_directory’); ?>/styleMSIE.css” type=”text/css” media=”screen”/
   > <?php } else { ?> <link rel=”stylesheet” href=”<?php bloginfo(‘stylesheet_url’);?
   >” type=”text/css” media=”screen” /> <?php } ?>
 * but this does not work unless I previously included the browser-detection…
    (
   syntax errors in this post are typoes)
 * TIA (a lot of)
    david

Viewing 10 replies - 1 through 10 (of 10 total)

 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-209750)
 * Theme Wuhan does exactly what you’re looking for by placing these lines in the
   Header template (header.php):
 * `<?php if (eregi("MSIE",getenv("HTTP_USER_AGENT")) ||
    eregi("Internet Explorer",
   getenv("HTTP_USER_AGENT"))) { ?><link rel="stylesheet" type="text/css" href="
   <?php bloginfo('stylesheet_directory'); ?>/style-ie.css"/> <?php } else { ?>
 * <link rel="stylesheet" type="text/css" href="<?php bloginfo('stylesheet_directory');?
   >/style.css"/>
 * <?php } ?>
 *  [mogwai](https://wordpress.org/support/users/mogwai/)
 * (@mogwai)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-209950)
 * Sorry, but as I got no reply on this earlier on I just had to ask again.
    Does
   anybody know if this is also possible with complete themes?
 * i.e. let this script change a theme by adressing the theme switcher plug-in (
   by ryan boren)?
 *  Moderator [James Huff](https://wordpress.org/support/users/macmanx/)
 * (@macmanx)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210031)
 * Read the post that I made, just before you posted. It describes the technique
   used in Theme Wuhan, which is a complete theme.
 *  [Firas](https://wordpress.org/support/users/firas/)
 * (@firas)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210037)
 * mogwai, switching themes based on browser might be a bit complex–you’ll probably
   need to do it in the root/index.php so that you don’t see a flash of one theme
   and then see another–but it’s probably possible to send a query to the theme 
   switcher plugin to do it.
 *  [mogwai](https://wordpress.org/support/users/mogwai/)
 * (@mogwai)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210042)
 * [@firas](https://wordpress.org/support/users/firas/)
    Yes – that’s what my question
   was about! Sending a query to the theme switcher plug-in. But nobody seems to
   know how…
 *  [Firas](https://wordpress.org/support/users/firas/)
 * (@firas)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210376)
 * Ok, I think I have this.
 * Replace the index.php in your wordpress root with this:
 * `<?php`
 * if(empty($_COOKIE['ThemeSwitched'])) {
    if (eregi("MSIE",getenv("HTTP_USER_AGENT"))
   || eregi("Internet Explorer",getenv("HTTP_USER_AGENT"))) { setcookie('ThemeSwitched','
   true'); header('Location: /?wptheme=WordPress+Classic'); } else { setcookie('
   ThemeSwitched', 'true'); header('Location: /?wptheme=WordPress+Default'); } }
 * define('WP_USE_THEMES', true);
    require('./wp-blog-header.php'); ?>
 * If your WordPress install is not accessible from your site root, then replace
   the two `header('Location: /?wptheme=` with `header('Location: http://example/?
   wptheme=`, example being the path you put in your browser to access your blog(
   eg. `http://example.com/blog`).
 * Replace `wptheme=WordPress+Classic` and `wptheme=WordPress+Default` with the 
   actual queries for the theme switcher for the themes you want to load. The first
   query is if the browser is IE, the second is if it’s not IE (so in the example
   code above, IE gets the Classic theme.)
 * To see what query to send to the theme switcher, do a call to `<?php wp_theme_switcher();?
   >` somewhere in your template and see the URL it points to to load your preferred
   theme.
 *  [mogwai](https://wordpress.org/support/users/mogwai/)
 * (@mogwai)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210393)
 * Thanks a lot for the info! I will try this later on. One thing missing is a message
   that would inform visitors that cookies need to be enabled…
 *  [Leffe](https://wordpress.org/support/users/leffe/)
 * (@leffe)
 * [21 years ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210394)
 * Include vars.php and use the variables defined in it.
 *  [gamehall](https://wordpress.org/support/users/gamehall/)
 * (@gamehall)
 * [19 years, 10 months ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210642)
 * thanks for the help, someone knows if this techinique work ?
 *  Moderator [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * (@otto42)
 * WordPress.org Admin
 * [19 years, 10 months ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210643)
 * > (I need this to serve MSIE a different stylesheet, and some script-stuff)
 * The correct way to do this is to use conditional comment tags in the page itself.
   `
   <!--[if IE]> <link rel="stylesheet" type="text/css" media="screen" href="/ie-
   stylesheet.css" /> <![endif]-->
 * You can even be version specific, if you like:
    `<!--[if IE 5]> ... <![endif]--
   >
 * Or even a variety of versions:
    `<!--[if gte IE 5]> ... <![endif]-->
 * “gte” means greater than or equal to. There’s also lt, lte, and gt.
 * This doesn’t work with just CSS, but with anything you like:
    `<!--[if IE]> <
   h1>Welcome IE User!</h1> <![endif]-->
 * Firefox and other browsers will ignore these entirely, as they’re in comment 
   tags.
 * To work the other way, the non-standard comment tag comes in handy:
    `<comment
   >You are not using IE.</comment>`
 * IE will ignore the stuff in the comment tags, other browsers won’t.

Viewing 10 replies - 1 through 10 (of 10 total)

The topic ‘simple: Browser detection?’ is closed to new replies.

## Tags

 * [ThemeSwitcher](https://wordpress.org/support/topic-tag/themeswitcher/)

 * 10 replies
 * 7 participants
 * Last reply from: [Samuel Wood (Otto)](https://wordpress.org/support/users/otto42/)
 * Last activity: [19 years, 10 months ago](https://wordpress.org/support/topic/simple-browser-detection/#post-210643)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
