你可以用其他讨厌的黑客来解决这个问题,但这里有一种类似WordPress的方法:
In your header.php
<?php
// User is not using mobile
if( ! wp_is_mobile() ) {
wp_nav_menu(); // Your "original menu"
}
// User is using mobile
else if( wp_is_mobile() ) {
wp_nav_menu(); // Your another menu that only has top level items
}
?>
请记住
wp_is_mobile()
还将平板电脑视为移动设备,您应该始终仔细考虑这一点,因为如果将PC窗口调整为小/窄->则显然不将其视为移动设备。
And jQuery to disable your click event:
var isMobile = false;
// Check if user is using mobile device
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
isMobile = true;
}
if( ! isMobile ) {
// Your usual click event
}