サイトアイコン マーカーネット株式会社

【WordPress】WPtouchプラグインを利用した場合、特定のURLのみPCサイトを表示させる方法。

【WordPress】WPtouchプラグインを利用した場合、特定のURLのみPCサイトを表示させる方法。

WordPressのプラグイン「WPtouch」をインストールし
スマホサイトを制作する際、特定のURLのときはPC用のテンプレートを
表示させたい場合がございます。その方法をご紹介します。

wptouch のPC/スマフォ判定は、

 /wp-content/plugins/wptouch/wptouch.php の

detectAppleMobile() で処理しています。

$this->applemobile = true;  だと スマフォテンプレを読み込み、
$this->applemobile = false; だと   PCテンプレを読み込む仕組みです。

【修正方法】
・PHPで現在のURLを取得し、
特定の文字列を含むURLを判定し、true/false を切り替えます。

– 抜粋 start–
function detectAppleMobile($query = ”) {
$container = $_SERVER[‘HTTP_USER_AGENT’];
// The below prints out the user agent array. Uncomment to see it shown on the page.
// print_r($container);
$this->applemobile = false;
$useragents = bnc_wptouch_get_user_agents();
$exclude_agents = bnc_wptouch_get_exclude_user_agents();

  foreach ( $useragents as $useragent ) {

    if ( preg_match( “#$useragent#i”, $container ) ) {

      // $this->applemobile = true;
// break;

      // 追加
      if ( 特定のURLであれば ・・・) {
                            $this->applemobile = true;
                            break;
                     } else {

                           $this->applemobile = false;
                            break;
                       }

}
}

     if ( $this->applemobile ) {
foreach( $exclude_agents as $agent ) {
if ( preg_match( “#$agent#i”, $container ) ) {
//echo “FALSE!!!!”;
$this->applemobile = false;
break;
}
}
}
}
— 抜粋 end–

モバイルバージョンを終了