Add items to a menu dynamically

You could achieve this with a custom walker function, on your menu. a very simple example: class Walker_WPA82563_Submenu extends Walker_Nav_Menu { function end_el(&$output, $item, $depth=0, $args=array()) { if( ‘Boats’ == $item->title ){ $output .= ‘<ul><li>Dynamic Subnav</li></ul>’; } $output .= “</li>\n”; } } Then where you call the nav menu, create an instance of your custom … Read more

Get menu links only

Use a custom walker: class WPSE_33175_Simple_Walker extends Walker { public function walk( $elements, $max_depth ) { $list = array (); foreach ( $elements as $item ) $list[] = “<a href=”https://wordpress.stackexchange.com/questions/33175/$item->url”>$item->title</a>”; return join( “\n”, $list ); } } … and then call wp_nav_menu() like this: wp_nav_menu( array ( ‘theme_location’ => ‘your_registered_theme_location’, ‘walker’ => new WPSE_33175_Simple_Walker, ‘items_wrap’ … Read more

Bar separated navigation by extending Walker_Nav_Menu

You can use the menu order inside the item to see if it’s not first. If it isn’t have it draw the character before the anchor. class Bar_List_Walker_Nav_Menu extends Walker_Nav_Menu { private $separator = ” | “; function start_el(&$output, $item, $depth, $args) { if($item->menu_order > 1){ $output .= $this->separator; } $attributes = ! empty( $item->target … Read more

How can I disable parent menu item links?

Do not create fake URLs (#). This would be very bad for users with a screen reader: the are using a list of available links to browse your site. The same is true for javascript: links, they are not exactly elegant markup anyway. You need two steps: Mark the items with children before the walker … Read more

Remove navigation from header in custom page template

Use a conditional tag: Codex References: Function Reference (is_page) Function Reference (Conditional Tags) You can specify the landing page by Page ID, Page Title or Page Slug. Here is an example: <?php if ( !is_page( ‘landing-page’ ) ) { wp_nav_menu( array( ‘show_home’ => ‘Home’, ‘container’ => ‘false’, ‘theme_location’ => ‘main’) ); } endif; ?> It … Read more

if role is logged in then do something

Something like this would be more efficient. This is basic PHP by the way, not WP specific. function add_extra_item_to_nav_menu( $items, $args ) { $roles = [ ‘administrator’ => [ //Role – slug name ‘SCHOOL_NAME-A’, //url path – appended to the end ‘ADMIN’, // can be any name – appended to SHOP NOW button ], ‘ROLEABC’ … Read more

wp_get_nav_menu_items order doesn’t work

When you look in WordPress source code, you will find reason for that. On line 538 of nav-menu.php you’ll find: if ( ARRAY_A == $args[‘output’] ) { $GLOBALS[‘_menu_item_sort_prop’] = $args[‘output_key’]; usort($items, ‘_sort_nav_menu_items’); $i = 1; foreach( $items as $k => $item ) { $items[$k]->$args[‘output_key’] = $i++; } } I didn’t check why, but it looks … Read more