vendredi 23 avril 2021

Make dropdown parent unclickable on mobile but stay clickable on desktop

What's the correct use of wp_is_mobile() here? I've been trying to make my dropdown menu parent unclickable for mobile devices but remain clickable on desktop devices.

    if (wp_is_mobile() && $depth === 0 && in_array ( 'menu-item-has-children', $classes ) ) {
            
                $atts['class']         .= ' dropdown-toggle';
            $atts['data-toggle']   = 'dropdown';
            $atts['id']            = 'navbar-dropdown-menu-link-' . $item->ID;
            $atts['aria-haspopup'] = "true";
            $atts['aria-expanded'] = "false";
            $atts['href']          = '#';
                
        }  else {

            //$atts['data-toggle']   = 'dropdown';
            $atts['id']            = 'navbar-dropdown-menu-link-' . $item->ID;
            $atts['aria-haspopup'] = "true";
            $atts['aria-expanded'] = "false";
            //$atts['href']          = '#';
            $atts['href']          = ! empty( $item->url ) ? $item->url : ''; 
};

Aucun commentaire:

Enregistrer un commentaire