开发者 |
mindshare
MartyThornley |
---|---|
更新时间 | 2015年9月8日 11:12 |
捐献地址: | 去捐款 |
WordPress版本: | 4.3 |
<?php if(is_firefox($version)) { /* your code here */ }; ?>
<?php if(is_safari($version)) { /* your code here */ }; ?>
<?php if(is_chrome($version)) { /* your code here */ }; ?>
<?php if(is_opera($version)) { /* your code here */ }; ?>
<?php if(is_ie($version)) { /* your code here */ }; ?>
<?php if(is_browser($name, $version)) { /* your code here */ }; ?>
Check for mobile, tablet, iPhone, iPad, iPod, etc...
<?php if(is_desktop()) { /* your code here */ }; ?>
<?php if(is_tablet()) { /* your code here */ }; ?>
<?php if(is_iphone($version)) { /* your code here */ }; ?>
<?php if(is_ipad($version)) { /* your code here */ }; ?>
<?php if(is_ipod($version)) { /* your code here */ }; ?>
<?php if(is_mobile()) { /* your code here */ }; ?>
Check for greater than / less than a specific version...
Less than or equal to Firefox 19:
<?php if(is_firefox() && get_browser_version() <= 19) { /* your code here */ }; ?>
Less than or equal to IE 10:
<?php if(is_ie() && get_browser_version() <= 10) { /* your code here */ }; ?>
Greater than or equal to Safari 4:
<?php if(is_safari() && get_browser_version() >= 4) { /* your code here */ }; ?>
these are just a few examples, but this syntax will work for any browser or version.
Check specific versions...
Is the browser IE6?
<?php if(is_ie(6)) { /* your code here */ }; ?>
Is the browser IE10?
<?php if(is_ie(10)) { /* your code here */ }; ?>
Or you can get all the info and do what you want with it:
Get just the name...
<?php $browser_name = get_browser_name(); ?>
Get the full version number - 3.2, 5.0, etc...
<?php $browser_version = get_browser_version(); ?>
Or get it all in array...
<?php $browser_info = php_browser_info(); ?>
Shortcodes:
Test for specific browsers:
`
[is_browser name="chrome" version="45"]
You are using Chrome 45 or above.
[/is_browser]
*Output all browser info:*
[browser_info]`
php-browser-detection
folder to the /wp-content/plugins/
directory.This means the local cached copy of the browscap.ini user agent database is out of date. You can fix this by updating the file yourself manually, or wait for a new release of the plugin. To update the file, download the most recent version here: http://browscap.org/stream?q=PHP_BrowsCapINI and save it over the one bundled with the plugin php-browser-detection/cache/browscap.ini
This most likely means your web host is running a very old version of PHP. As of version 3.0, only PHP 5.3 and above are supported. You can ask your host to upgrade PHP for you.
$browser_info = php_browser_info();