Tag Info

New answers tagged

0

Here's one way to do it with the help of the menu CSS classes: For the menu item that you want to modify the label of, add the wpse_menu class to it: This is supported with: /** * Modify the title of menu items that contain the 'wpse_menu' class. * We restrict this to the primary menu. */ add_filter( 'wp_nav_menu_objects', function( $items, ...


0

Expanding on @Eugene's answer, if you want to limit this to a specific menu, just check the term ID of the menu: function custom_nav_args($args){ $menu = $args['menu']; if($menu->term_id = 17) /* replace term_id with menu id, or use $menu->name to do it by menu name*/ { $args['walker'] = new My_Custom_Walker(); } return $args; ...


0

What i have understand that you want to change the class of all li element to be what you want try this class myWalker extends Walker_Nav_Menu { function start_lvl(&$output, $depth = 0, $args = array()) { $output .= "\n".'<li class="your_custom_class" id ="your_custom_id>'."\n"; } function end_lvl(&$output, $depth = 0, ...


0

I think you should probably use wp_list_categories(), which even has parameters for a count, like e.g. show_count and pad_counts. Additionally it supports custom walkers via the walker parameter, but the walker would be based on Walker_Category - source -, which gives you every additional styling option you want.


0

Use menu_item_parent instead of menu-item-parent Can you show us the html output you want ?


0

Flexibility & cleanliness. Walker-based classes are an excellent way to generate custom output based on any branched data object. They keep your code lean, mean, and easily readable. You can define output for the start and end of each "branch" (any menu item with sub-menu items) as well as the start and/or end of each individual node/menu item. It's my ...


0

Use the default walker, it covers 99.999999999999.... ... 999999999999% of instances via its filters, and it's maintained by someone smarter than both of us, and used by a lot of people. If you need to do something that requires modifying the walker, use a subclass. Otherwise you're going to lose compatibility with anything that uses the walker filters, ...


1

I would say mostly you see the usage of wp_nav_menu(), which does use wp_get_nav_menu_items(). You can use wp_nav_menu() with the default walker or a custom walker. To be honest I can't remember the time I did a menu manually, with wp_get_nav_menu_items() or something else, and I tend to be lazy, so this is definitely more work. The Walker Class gives ...



Top 50 recent answers are included