Я закончил с использованием этого:
<?php
/* USER-AGENTS
================================================== */
function check_user_agent ($type = NULL) {
$user_agent = strtolower ($_SERVER['HTTP_USER_AGENT']);
if ($type == 'bot') {
// matches popular bots
if (preg_match ("/googlebot|adsbot|yahooseeker|yahoobot|msnbot|watchmouse|pingdom\.com|feedfetcher-google/", $user_agent)) {
return true;
// watchmouse|pingdom\.com are "uptime services"
}
} else if ($type == 'browser') {
// matches core browser types
if (preg_match ("/mozilla\/|opera\//", $user_agent)) {
return true;
}
} else if ($type == 'mobile') {
// matches popular mobile devices that have small screens and/or touch inputs
// mobile devices have regional trends; some of these will have varying popularity in Europe, Asia, and America
// detailed demographics are unknown, and South America, the Pacific Islands, and Africa trends might not be represented, here
if (preg_match ("/phone|iphone|itouch|ipod|symbian|android|htc_|htc-|palmos|blackberry|opera mini|iemobile|windows ce|nokia|fennec|hiptop|kindle|mot |mot-|webos\/|samsung|sonyericsson|^sie-|nintendo/", $user_agent)) {
// these are the most common
return true;
} else if (preg_match ("/mobile|pda;|avantgo|eudoraweb|minimo|netfront|brew|teleca|lg;|lge |wap;| wap /", $user_agent)) {
// these are less common, and might not be worth checking
return true;
}
}
return false;
}
?>
, а затем:
<?php
$ismobile = check_user_agent('mobile');
if($ismobile) {
wp_nav_menu(array('theme_location' => 'mobile'));
} else {
wp_nav_menu(array('menu' => 'primary', 'container' => '', 'menu_id' => 'menu'));
}
?>
Это не работает с размером устройства, а зависит от того, доступен ли сайт с мобильного устройства.
Источник: Detect mobile browser
Благодаря
Willem
Привет Эндрю Спасибо за ответ, я не хочу, чтобы держаться подальше от дисплея: нет причин для SEO. Поэтому я действительно ищу способ только вызвать соответствующий php для того, что подходит для любого меню. Thanks – Willem
Вы можете перемещать дисплей: none to css, но я не уверен, что это влияет на SEO или нет. На самом деле вы должны попробовать дизайн ответа, который вообще не использует Javascript, например: @media all и (min-width: 959px) {} – Andrew
Моя забота о SEO в два раза: поскольку структуры меню будут очень похожими, m касается дублированного контента, тем более, что он будет отображаться на каждой странице. Моя вторая проблема заключается в том, что Google хмурится скрытыми элементами. Спасибо – Willem