フッターphp ”if elseif” で条件分岐(モバイル・PC 総研問合せバナー)

【まずは、モバイルであるか否かを振り分ける関数 ua_smt を functions.php に記述】

<?php
function ua_smt (){
$ua = $_SERVER[‘HTTP_USER_AGENT’];
$ua_list = array(‘iPhone’,’iPad’,’iPod’,’Android’);
foreach ($ua_list as $ua_smt) {
if (strpos($ua,$ua_smt) !== false){return true;}
} return false;
}
?>
【ここまでで関数の記述はおわり。 モバイルであれば ua_smt関数は true を返し、PCであれば false を返す。 】

モバイルとPCを分けるだけなら問題はないが、今回はトップページにのみ実行させたいので、
モバイル 且つ トップページなら、この画像を表示。 PC 且つ トップページならこの画像を表示 としたいため、下記を記述。

<?php if (ua_smt() == true and is_front_page() == true ): ?>  ←モバイル 且つ トップページ
<div id=”footerFloatingMenu”>  ←idの内容は、CSS に記述済み
<a href=”http://souken.ch-j.co.jp/contact/” target=”_blank”><img src=”http://souken.ch-j.co.jp/wp-content/uploads/2018/04/sk_0406-16.jpg”></a>
</div>

<?php elseif (ua_smt() == false && is_front_page() ): ?>   ←PC 且つ トップページ
<div id=”footerFloatingMenu”>
<a href=”http://souken.ch-j.co.jp/contact/” target=”_blank”><img src=”http://souken.ch-j.co.jp/wp-content/uploads/2018/04/sk_0406-18.jpg”></a>
</div>

<?php endif ?>