Conflict with wp_is_mobile() conditional tag

WordPress Event Management, Calendars & Registration Forums Report A Bug Conflict with wp_is_mobile() conditional tag

This topic contains 3 replies, has 2 voices, and was last updated by  Stephen Harris 7 years, 3 months ago.

Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #25739

    I use wp_is_mobile() conditional tag to show different menu items on mobile via “Menu Items Visibility Control” plugin.

    I realized wp_is_mobile() conditional tag is not working after some time on my website.
    Whenever I deactivate Event Organizer Pro it works again.

    Any idea how I can use both plugins simultaneously?

    Adnan Akbas
    #25741

    Hi Adnan,

    Can you confirm that the problem is with wp_is_mobile() specifically (print outs its return value, and var_dum($_SERVER) – (we are particularly interested in $_SERVER['HTTP_USER_AGENT']).

    In short wp_is_mobile() does nothing but check the value of $_SERVER['HTTP_USER_AGENT'] (See source) and Event Organiser (Pro) does nothing to that value, so I don’t think Event Organiser Pro – by itself – can be causing wp_is_moble() to return an incorrect value.

    More plausible is that Pro and Menu Items Visibility Control are conflicting in some other way.

    Stephen Harris
    #25744

    Hi Stephen,

    thanks for your quick answer. Instead of using the plugin, I added my own code like:

       if(wp_is_mobile() && $args->theme_location == 'primary') {        
                $items .= ...my-menu-item....
            return $items;
        } else {
            return $items;
        }
    }
    add_filter( 'wp_nav_menu_items', 'add_mobile_nav', 10, 2 );
    

    which works fine. That means you are right. wp_is_mobile() is not the problem.
    Should be something else. Job is done. Thank you!

    Adnan Akbas
    #25778

    Glad you’ve found something that works for you.

    Stephen Harris
Viewing 4 posts - 1 through 4 (of 4 total)
To enable me to focus on Pro customers, only users who have a valid license for the Pro add-on may post new topics or replies in this forum. If you have a valid license, please log-in or register an account using the e-mail address you purchased the license with. If you don't you can purchase one here. Or there's always the WordPress repository forum.