Tag Info

New answers tagged

0

@raunak how about use jQuery jQuery(" ul li .menu-item").removeClass( "current" ); for adding to parent jQuery(".current-menu-parent").addClass( "current" );


0

Your html structure should look like <ul class="parent-class"> <li>Page 1</li> <li> <ul class="child-class"> <li> Sub menu item 1</li> <li> Sub menu item 2</li> </ul> </li> </ul> Wordpress should automatically add an "active" class to the active page then ...


6

Using a custom Walker, the start_el() method has access to $depth param: when it is 0 the elemnt is a top one, and we can use this info to maintain an internal counter. When the counter reach a limit, we can use DOMDocument to get from full HTML output just the last element added, wrap it in a submenu and add it again to HTML. Edit When the number of ...


4

Got a working function, but not sure if it is the best solution. I used a custom walker: class Custom_Walker_Nav_Menu extends Walker_Nav_Menu { function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) { global $wp_query; $indent = ( $depth ) ? str_repeat( "\t", $depth ) : ''; $classes = empty( $item->classes ) ? ...


7

There even is a way to make this possible with CSS alone. This has some limitations, but I still thought it might be an interesting approach: Limitations You need to hardcode the width of the dropdown Browser-Support. You basically need CSS3 selectors. But everything from IE8 up should work, although I haven't tested this. This is more of a ...


6

You can use wp_nav_menu_items filter. It accepts menu output and arguments which hold menu attributes, like menu slug, container, etc. add_filter('wp_nav_menu_items', 'wpse_180221_nav_menu_items', 20, 2); function wpse_180221_nav_menu_items($items, $args) { if ($args->menu != 'my-menu-slug') { return $items; } // extract all ...



Top 50 recent answers are included