Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #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!

    #714582

    Hey!

    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.
    #714798

    Ok, I will give this a try. Thank you Yigit!

    #714849

    Hi,

    You are welcome!
    We will keep the thread open and will wait to hear from you :)

    Best regards,
    Yigit

Viewing 4 posts - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.