Tagged: conditional logic, menu
-
AuthorPosts
-
November 18, 2016 at 5:25 am #713822
I have a problem with a game on the site I am building. In most browsers, it works great right on the page. But on one browser, I need to send the user to a different page. So, I am thinking that I need a menu item that shows for only one browser and another menu item that shows for all other browsers. Detecting the browser type in php is easy. I know there is conditional logic in menu items, but is there a way to react from a php function? By the way, php for determining browser:
function get_browser_name($user_agent) { if (strpos($user_agent, 'Opera') || strpos($user_agent, 'OPR/')) return 'Opera'; elseif (strpos($user_agent, 'Edge')) return 'Edge'; elseif (strpos($user_agent, 'Chrome')) return 'Chrome'; elseif (strpos($user_agent, 'Safari')) return 'Safari'; elseif (strpos($user_agent, 'Firefox')) return 'Firefox'; elseif (strpos($user_agent, 'MSIE') || strpos($user_agent, 'Trident/7')) return 'IE'; return 'Other'; } // USAGE // echo get_browser_name($_SERVER['HTTP_USER_AGENT']);
Thanks!
November 20, 2016 at 9:07 pm #714582Hey!
Please go to Appearance > Menus and create a new menu which is a duplicate of your main menu minus the menu item you would not like to display and then add following code to functions.php file in Appearance > Editor
function avia_menu_browser_detect( $args = '' ) { global $is_lynx, $is_gecko, $is_IE, $is_opera, $is_NS4, $is_safari, $is_chrome, $is_iphone; if($is_IE) { $args['menu'] = 'main-menu-two'; } else { $args['menu'] = 'main-menu'; } return $args; } add_filter( 'wp_nav_menu_args', 'avia_menu_browser_detect' );
Your alternative main menu which is named main-menu-two in example will be displayed on IE and your “main” main menu which is named main-menu in example, will be displayed on all other browsers
Regards,
Yigit- This reply was modified 7 years, 11 months ago by Yigit.
November 21, 2016 at 1:32 pm #714798Ok, I will give this a try. Thank you Yigit!
November 21, 2016 at 3:47 pm #714849 -
AuthorPosts
- You must be logged in to reply to this topic.