[WordPress] 外掛分享: Nginx Mobile Theme

首頁外掛目錄 › Nginx Mobile Theme
WordPress 外掛 Nginx Mobile Theme 的封面圖片
200+
安裝啟用
★★★★★
5/5 分(2 則評價)
2708 天前
最後更新
問題解決
WordPress 3.7.1+ v1.8.2 上架:2013-11-07

內容簡介

這個外掛允許您根據 Nginx 反向代理中的 User Agent 切換主題。

Nginx Mobile Theme 插件的要求如下:

PHP 5.3 或更新版本
WordPress 3.7 或更新版本
Nginx Cache Controller 2.0.0 或更新版本

一些功能

您可以透過 Nginx Cache Controller自動清除手機和電腦的每個緩存資料。
根據使用者代理切換主題。
允許您通過過濾器書鉤自定義多個移動設備支持。

Nginx 配置

將移動設備檢測添加到 nginx.conf 中。

set $mobile '';
if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') {
set $mobile "@smartphone";
}

設置 proxy_cache_key。

proxy_cache_key "$mobile$scheme://$host$request_uri";

向後端發送自定義請求標頭。

proxy_set_header X-UA-Detect $mobile;

當在 $_SERVER['HTTP_X_UA_DETECT'] 收到 ‘@smartphone’ 時,Nginx Mobile Theme 將切換主題。

使用方法

請訪問 WordPress 管理區域中的主題自定義。
在下拉式菜單中選擇 Mobile Theme。
點擊「保存並發佈」按鈕進行保存。

多個移動設備支持

將自定義移動設備檢測添加到 nginx.conf 文件中。
通過 nginxmobile_mobile_detects 過濾器挂鉤將自定義移動設備檢測添加到 WordPress 中。

nginx.conf:
set $mobile ”;
if ($http_user_agent ~* ‘(iPhone|iPod)’) {
set $mobile “@smartphone”;
}
if ($http_user_agent ~* ‘iPad’) {
set $mobile “@tablet”;
}

在您的自定義插件中:
add_filter(‘nginxmobile_mobile_detects’, function(){
return array(‘@smartphone’, ‘@tablet’);
});

由此,您可以在主題自定義中單獨為 @smartphone 和 @tablet 選擇主題。

Amimoto 支援

Amimoto 是在 AWS EC2 上完美調整的 WordPress AMI。

在第 17 行取消 /etc/nginx/conf.d/default.conf 的註釋。

之前:
#include /etc/nginx/mobile-detect;

之後:
include /etc/nginx/mobile-detect;

在 /etc/nginx/nginx.conf 中添加以下行。

之前:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding “”;

之後:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding “”;
proxy_set_header X-UA-Detect $mobile; # 新增一行

定義 wp-config.php 中的常量

define(‘IS_AMIMOTO’, true);

外掛標籤

開發者團隊

⬇ 下載最新版 (v1.8.2) 或搜尋安裝

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

原文外掛簡介

This plugin allows you to switch theme according to the User Agent on the Nginx reverse proxy.
Nginx Mobile Theme’s requirements are as follows.

PHP 5.3 or later
WordPress 3.7 or later
Nginx Cache Controller 2.0.0 or later

Some Features

You can flush mobile’s and pc’s each caches automatically via Nginx Cache Controller.
Allow you to switch theme according to the user-agent.
Allow you to customize multiple mobile device support via filter-hook.

Nginx Configuration
Add mobile device detection to the nginx.conf.
set $mobile '';
if ($http_user_agent ~* '(iPhone|iPod|incognito|webmate|Android|dream|CUPCAKE|froyo|BlackBerry|webOS|s8000|bada|IEMobile|Googlebot\-Mobile|AdsBot\-Google)') {
set $mobile "@smartphone";
}

Set proxy_cache_key.
proxy_cache_key "$mobile$scheme://$host$request_uri";

Send custom request header to the backend.
proxy_set_header X-UA-Detect $mobile;

Nginx Mobile Theme will switch theme when ‘@smartphone’ is received in the $_SERVER['HTTP_X_UA_DETECT'].
How to use

Please access to the theme-customizer in the WordPress admin area.
Please select Mobile Theme in the drop-down.
Click “Save & Publish” button to save.

Multiple mobile device support

Add custom mobile detection to the nginx.conf.
Add custom mobile detection to the WordPress via nginxmobile_mobile_detects filter-hook.

nginx.conf:
set $mobile ”;
if ($http_user_agent ~* ‘(iPhone|iPod)’) {
set $mobile “@smartphone”;
}
if ($http_user_agent ~* ‘iPad’) {
set $mobile “@tablet”;
}
In your custom plugin:
add_filter(‘nginxmobile_mobile_detects’, function(){
return array(‘@smartphone’, ‘@tablet’);
});

As a result, allow you to select theme for @smartphone and @tablet individually in the theme-customizer.

Amimoto Support
The Amimoto is a full-tuned WordPress AMI on the AWS EC2.

Uncomment /etc/nginx/conf.d/default.conf in line 17

before:
#include /etc/nginx/mobile-detect;
after:
include /etc/nginx/mobile-detect;

Add line to /etc/nginx/nginx.conf like following.

before:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding “”;
after:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding “”;
proxy_set_header X-UA-Detect $mobile; # add new line

Define constant in the wp-config.php
define(‘IS_AMIMOTO’, true);

延伸相關外掛

文章
Filter
Mastodon