I'm using the following function, as described here:


Now when I use the following css styles, it does exactly what I want in Safari and Chrome:

.safari li#linkrss {margin-top: -15px;}
.chrome li#linkrss {margin-top: -15px;}

When I try .gecko li#linkrss {margin-top: 0px;} for Firefox, however, it doesn't seem to apply. For example, when I inspect the css element using FireBug, it shows the style for Safari. Any tips on how to fix this?

  • You mean the global $is_gecko variable is not being set to true in Firefox (what's the version, btw?); if this is correct then WordPress is not detecting your Firefox correctly, and assuming it is $is_safari. Can you dump these globals to make sure that Firefox is getting recognized as $is_safari instead? Do you have some header-altering Firefox plugins enabled? Disable all Firefox plugins. – soulseekah Apr 2 '12 at 1:45

Can't tell you exactly why but that function didnt work for me either..
Finally i have found this script i have modified a little bit here: get_browser()

Here it is (in your functions.php):

function whatBrowser() {
    define("UNKNOWN", 0);
    define("TRIDENT", 1);
    define("GECKO", 2);
    define("PRESTO", 3);
    define("WEBKIT", 4);
    define("VALIDATOR", 5);
    define("ROBOTS", 6);

    if(!isset($_SESSION["info"]['browser'])) {
        $_SESSION["info"]['browser']['engine'] = UNKNOWN;
        $_SESSION["info"]['browser']['version'] = UNKNOWN;
        $_SESSION["info"]['browser']['platform'] = 'Unknown';

        $navigator_user_agent = ' ' . strtolower($_SERVER['HTTP_USER_AGENT']);

        if (strpos($navigator_user_agent, 'linux')) :
            $_SESSION["info"]['browser']['platform'] = 'Linux';
        elseif (strpos($navigator_user_agent, 'mac')) :
            $_SESSION["info"]['browser']['platform'] = 'Mac';
        elseif (strpos($navigator_user_agent, 'win')) :
            $_SESSION["info"]['browser']['platform'] = 'Windows';

        if (strpos($navigator_user_agent, "trident")) {
            $_SESSION["info"]['browser']['engine'] = TRIDENT;
            $_SESSION["info"]['browser']['version'] = floatval(substr($navigator_user_agent, strpos($navigator_user_agent, "trident/") + 8, 3));
        elseif (strpos($navigator_user_agent, "webkit")) {
            $_SESSION["info"]['browser']['engine'] = WEBKIT;
            $_SESSION["info"]['browser']['version'] = floatval(substr($navigator_user_agent, strpos($navigator_user_agent, "webkit/") + 7, 8));
            elseif (strpos($navigator_user_agent, "presto")) {
            $_SESSION["info"]['browser']['engine'] = PRESTO;
            $_SESSION["info"]['browser']['version'] = floatval(substr($navigator_user_agent, strpos($navigator_user_agent, "presto/") + 6, 7));
        elseif (strpos($navigator_user_agent, "gecko")) {
            $_SESSION["info"]['browser']['engine'] = GECKO;
            $_SESSION["info"]['browser']['version'] = floatval(substr($navigator_user_agent, strpos($navigator_user_agent, "gecko/") + 6, 9));
        elseif (strpos($navigator_user_agent, "robot"))
            $_SESSION["info"]['browser']['engine'] = ROBOTS;
        elseif (strpos($navigator_user_agent, "spider"))
            $_SESSION["info"]['browser']['engine'] = ROBOTS;
        elseif (strpos($navigator_user_agent, "bot"))
            $_SESSION["info"]['browser']['engine'] = ROBOTS;
        elseif (strpos($navigator_user_agent, "crawl"))
            $_SESSION["info"]['browser']['engine'] = ROBOTS;
        elseif (strpos($navigator_user_agent, "search"))
            $_SESSION["info"]['browser']['engine'] = ROBOTS;
        elseif (strpos($navigator_user_agent, "w3c_validator")) 
            $_SESSION["info"]['browser']['engine'] = VALIDATOR;
        elseif (strpos($navigator_user_agent, "jigsaw"))
            $_SESSION["info"]['browser']['engine'] = VALIDATOR;

    echo $_SESSION['browser']['engine'];
        switch($_SESSION["info"]['browser']['engine']) {
            case UNKNOWN: echo "unknown";
            case TRIDENT: echo "trident";
            case GECKO: echo "gecko";
            case PRESTO: echo "presto";
            case WEBKIT: echo "Webkit";
            case VALIDATOR: echo "validator";
            case ROBOTS: echo "robot";

Then just change the body tag to this:

<body class="<?php whatBrowser(); ?>">

I tested it with chrome, IE & Firefox... worked gr8 for me..

Hope this Helps.
Best of luck, Sagive.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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