Highlighting wp_nav_menu() Ancestor Class w/o Children in Nav Structure?

There’s a simpler solution. Forget creating pages for each post type just so you can have nav items, because as you have learned, WP has no way of recognizing that the custom types you are browsing are related to that page. Instead, create a custom link in Appearance->Menus. Just put the URL that will return … Read more

Customizing Only a Specific Menu using the “wp_nav_menu_items” Hook?

To only add the custom search box to the main menu you could pass the second parameter provided by the wp_nav_menu_items filter and check if the theme_location is the primary location add_filter(‘wp_nav_menu_items’,’search_box_function’, 10, 2); function search_box_function( $nav, $args ) { if( $args->theme_location == ‘primary’ ) return $nav.”<li class=”menu-header-search”><form action=’http://example.com/’ id=’searchform’ method=’get’><input type=”text” name=”s” id=’s’ placeholder=”Search”></form></li>”; … Read more

Any docs for wp_nav_menu’s “items_wrap” argument?

The parameter ‘items_wrap’ for wp_nav_menu() defaults to: ‘<ul id=”%1$s” class=”%2$s”>%3$s</ul>’ This a a template that is parsed with sprintf(): $nav_menu .= sprintf( $args->items_wrap , esc_attr( $wrap_id ) // %1$s , esc_attr( $wrap_class ) // %2$s , $items // %3$s ); The numbered placeholders – %1$s, %2$s, %3$s – refer to the arguments after the first … Read more

Programmatically add a Navigation menu and menu items

I might be misunderstanding you, but why not use wp_create_nav_menu()? E.g., this is what I do to create a custom BuddyPress menu when I detect BP as active: $menuname = $lblg_themename . ‘ BuddyPress Menu’; $bpmenulocation = ‘lblgbpmenu’; // Does the menu exist already? $menu_exists = wp_get_nav_menu_object( $menuname ); // If it doesn’t exist, let’s … Read more