[WordPress] 外掛分享: PHP Browser Detection

首頁外掛目錄 › PHP Browser Detection
600+
安裝啟用
★★★★
4.1/5 分(16 則評價)
3844 天前
最後更新
問題解決
v3.1.8 上架:2010-01-28

內容簡介

版本3新增對於is_tablet()、is_desktop()和is_browser()函數的支援,同時進行了許多錯誤修正及程式碼優化。從版本3.1.2開始,browscap.ini的自動更新已被停用,直到我們解決了記憶體使用問題為止。

PHP Browser Detection是一個WordPress外掛,用於偵測使用者的瀏覽器。它可以用於為Internet Explorer發送條件性CSS檔案、在頁面上的任何位置顯示不同的內容或自訂訊息,以及為iPhone切換Flash為圖片。

樣板標籤:

測試特定的瀏覽器:

$version是可選的。包括主要版本號碼,單個整數-3、4、5等等... 或留空以測試任何版本。

<?php if(is_firefox($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_safari($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_chrome($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_opera($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_ie($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_browser($name, $version)) { /* 你的程式碼 */ }; ?>

檢查手機、平板電腦、iPhone、iPad、iPod等等...

<?php if(is_desktop()) { /* 你的程式碼 */ }; ?>

<?php if(is_tablet()) { /* 你的程式碼 */ }; ?>

<?php if(is_iphone($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_ipad($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_ipod($version)) { /* 你的程式碼 */ }; ?>

<?php if(is_mobile()) { /* 你的程式碼 */ }; ?>

檢查大於或小於特定版本...

小於或等於Firefox 19:
< ?php if(is_firefox() && get_browser_version()

小於或等於IE 10:
< ?php if(is_ie() && get_browser_version()

大於或等於Safari 4:
= 4) { /* 你的程式碼 */ }; ?>

這只是一些例子,但這個語法將適用於任何瀏覽器或版本。

檢查特定版本號碼...

瀏覽器是否為IE6?

瀏覽器是否為IE10?

或者你可以獲取所有信息並對其進行操作:

僅獲取名稱...

<?php $browser_name = get_browser_name(); ?>

獲取完整版本號碼 - 3.2、5.0等等...

<?php $browser_version = get_browser_version(); ?>

或者在數組中獲取全部資訊...

<?php $browser_info = php_browser_info(); ?>

短代碼:

測試特定瀏覽器:

[is_browser name="chrome" version="45"]
<p>你使用的是Chrome 45或更高版本。</p>
[/is_browser]

輸出所有瀏覽器資訊:

[browser_info]

外掛標籤

開發者團隊

⬇ 下載最新版 (v3.1.8) 或搜尋安裝

① 下載 ZIP → 後台「外掛 › 安裝外掛 › 上傳外掛」
② 後台搜尋「PHP Browser Detection」→ 直接安裝(推薦)
📦 歷史版本下載

原文外掛簡介

Version 3 adds support for is_tablet(), is_desktop(), and is_browser() as well as numerous bug fixes and code improvements. As of version 3.1.2 automatic updates of browscap.ini are disabeld until we can deal with memory usage issues.
PHP Browser Detection is a WordPress plugin used to detect a user’s browser. It can be used to send conditional CSS files for Internet Explorer, display different content or custom messages anywhere on the page, or to swap out Flash for an image for iPhones.
Template Tags:
Test for specific browsers:
$version is optional. Include a major version number, a single integer – 3,4,5, etc… Or leave it empty to test for any version.

Check for mobile, tablet, iPhone, iPad, iPod, etc…

Check for greater than / less than a specific version…
Less than or equal to Firefox 19:
< ?php if(is_firefox() && get_browser_version() Less than or equal to IE 10: < ?php if(is_ie() && get_browser_version() Greater than or equal to Safari 4: = 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?

Is the browser IE10?

Or you can get all the info and do what you want with it:
Get just the name…

Get the full version number – 3.2, 5.0, etc…

Or get it all in array…

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]

延伸相關外掛

文章
Filter
Apply Filters
Mastodon