[Support request] Filter for #generate-slideout-menu ?

Home Forums Support [Support request] Filter for #generate-slideout-menu ?

Home Forums Support Filter for #generate-slideout-menu ?

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #2392442
    akal

    Hi, I’m looking into a way to add custom attribute to the offcanvas menu (location : slideout).
    Right now, I’m using nav_menu_link_attributes filter and I’m able to add my attributes to the ul.slideout-menu > li > a elements.
    But I would prefer target the ul.slideout-menu tag (or parents like .main-nav or even the nav#generate-slideout-menu) using filter ?
    The only available filter I see for that is generate_menu_class but it’s only for the #site-navigation …
    https://docs.generatepress.com/article/generate_navigation_class/

    #2392742
    David
    Staff
    Customer Support

    Hi there,

    there is the nav_menu_css_class filter which appends the menu list element.

    https://developer.wordpress.org/reference/hooks/nav_menu_css_class/

    So you could try this:

    
    function db_slideout_menu_list_classes( $classes, $item, $args ) {
    
    	if ( 'slideout' === $args->theme_location ) {
    		$classes[] = "my-custom-class";
            }
    
    	return $classes;
    }
    add_filter( 'nav_menu_css_class' , 'db_slideout_menu_list_classes' , 10, 4 );
    #2393130
    akal

    Hi David, ok I see, I can add custom class to the LI. Is it possible to target the UL ? Thanks

    #2393151
    David
    Staff
    Customer Support

    Aah, try this one:

    
    function db_modify_nav_menu_args( $args ) {
    	
    	if( 'slideout' == $args['theme_location'] ) {
    		$args['menu_class'] = 'my-custom-class';
    	}
    
    	return $args;
    }
    add_filter( 'wp_nav_menu_args', 'db_modify_nav_menu_args' );
    
    #2393255
    akal

    David, many thanks for your help and patience ! I got it ^^
    https://developer.wordpress.org/reference/functions/wp_nav_menu/#source

    function db_modify_nav_menu_args( $args ) {
    	
    	if( 'slideout' == $args['theme_location'] ) {
    		//$args['menu_class'] = 'my-custom-class';
    		$args['items_wrap'] = '<ul id="%1$s" uk-scrollspy="cls:uk-animation-slide-top; delay:100; repeat: true" class="%2$s">%3$s</ul>';
    	}
    
    	return $args;
    }
    add_filter( 'wp_nav_menu_args', 'db_modify_nav_menu_args' );
    #2393738
    David
    Staff
    Customer Support

    Awesome, glad to be of help!

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