ユーザエージェント(User Agent、Webブラウザなど)を判別し、別ページを表示する
- 2008年12月15日 22時18分
- WordPress MU | plugins | tips
Internet Explorer 6を判別して別ページを表示するプラグインのサンプル。
IE6ハックとかやりたくないので作ってみました。「IE6には対応してないよ、ごめんなさい」というページを表示するだけ。
<?php
/*
Plugin Name: maaguu_replace_page.php
Plugin URI: http://wp.maaguu.com/2008/12/15/replace-page/
Description:
Version: 1.0
Author: maaguu
Author URI: http://maaguu.com/
*/
/* Copyright 2008 maaguu (email : info@mx.maaguu.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class maaguu_replacePage
{
private $userAgent;
private $pattern_ie6;
public function __construct()
{
$this->userAgent = $_SERVER['HTTP_USER_AGENT'];
$this->pattern_ie6 = '/MSIE 6/';
add_action('template_redirect', array($this, 'replace_page'));
}
public function replace_page()
{
if (preg_match($this->pattern_ie6, $this->userAgent))
{
include(TEMPLATEPATH . '/ie6.php');
exit;
}
}
}
new maaguu_replacePage();
/* End of file maaguu_replace_page.php */
プラグインを有効にして、テンプレートディレクトリにie6.phpを置きます。



コメントを残す