开发者

WP plugin based on useragent

I am writing a plugin which does some js stuff, but does not work for other browsers than FF . I've thought why not execute the plugin for the browsers which support it. I've added the code, but for some reason when I activate the plugin and check the site with a FF all开发者_如何学JAVA I get is blank page. If I visit with a IE the site is shown correctly. Basically my code is like this

$agent= strtolower($_SERVER['HTTP_USER_AGENT']); if (preg_match('/firefox/',$agent)){ include(plugins_url('script.js',FILE)); some more code }

So when I visit with FF I get blank page, when I visit with IE the blog loads normally


Use WordPress' built in browser detection:

add_hook('wp_head','custom_code');
function custom_code() {
    global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone;

    if($is_lynx) //do something
    elseif($is_gecko) //do something
    elseif($is_opera) //do something
    elseif($is_NS4) //do something
    elseif($is_safari) //do something
    elseif($is_chrome) //do something
    elseif($is_IE) //do something
    else //do something

    if($is_iphone) //do something
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜