Browser Detection with PHP and WordPress

PHP

This tutorial specifically deals with using this code in a WordPress header action hook. The premise is that we will get the HTTP_USER_AGENT to conditionally load a stylesheet for a particular browser. Of course any CSS should be browser-agnostic and work with nearly all modern systems, though sometimes it’s helpful to keep our fixes organized through different stylesheets.

//
// Browser Specific Stylesheet Loading
if(isset($_SERVER['HTTP_USER_AGENT'])) {

$agent = $_SERVER['HTTP_USER_AGENT'];

// Firefox
if(strlen(strstr($agent,"Firefox")) > 0 )
wp_enqueue_style( 'firefoxcss', get_stylesheet_directory_uri() . '/css/firefox.css' ); 

}