【发布时间】:2013-02-22 07:19:36
【问题描述】:
我在 Wordpress 安装中使用 Serbanghita's PHP Mobile Detect 类。我的 header.php 文件中有以下内容:
<?php
include 'php/Mobile_Detect.php';
$detect = new Mobile_Detect();
?>
当我将以下内容放在我的 single.php 文件中时,我收到一个关于非对象错误的调用:
<?php if ($detect->isMobile()) {
//Do something
} ?>
有什么想法吗?我无法将包含移动到我的 single.php 文件中,因为我需要在 header.php 中使用它,当然我不能将它复制到 single.php 文件中,因为那时我正在重新声明该类。
任何帮助,非常感谢。
【问题讨论】:
-
你可以使用这个 wordpress 内置功能 wp is mobile codex.wordpress.org/Function_Reference/wp_is_mobile