Adding a unique ID to each sub-menu

As far as I can know about menus in WordPress – handlers use menu arguments. You can try to use this. Using the argument filter, we can pass the ID of the item: add_filter( ‘nav_menu_item_args’, function( $args, $item, $depth ) { $args->item_id = $item->ID; return $args; }, 10, 3 ); Then use custom argument anywhere. … Read more

Is there a hook for nav menu item links to add custom css programatically?

Yes, there is, and the hook is nav_menu_link_attributes: apply_filters( ‘nav_menu_link_attributes’, array $atts, WP_Post $item, stdClass $args, int $depth ) Filters the HTML attributes applied to a menu item’s anchor element. For example, this adds the nav-link class to the <a> tag only if the theme location ($args->theme_location) is exactly my-location: add_filter( ‘nav_menu_link_attributes’, ‘my_nav_menu_link_attributes’, 10, 3 … Read more

Automatically add images to a menu

I guess you need this function get_the_post_thumbnail_url($menu->object_id); (provided menu item is not a custom link) $menu->ID is not the id of the post/page it is linking to. About calling meta yes it is also possible $image_url = get_post_meta( $menu->object_id, ‘meta_key’, true );

WordPress Nav Walker – Top menu link with dropdown link not clickable (dropdown opens)

Managed to fix it by updating the following: $attributes .= ( $args->walker->has_children ) ? ‘ class=”dropdown-toggle” data-toggle=”dropdown”‘ : ”; // THE PROBLEM! to: $attributes .= ( $args->walker->has_children ) ? ‘ ‘ : ”; // THE PROBLEM! And the fourth $item_output to: $item_output .= ( $depth == 0 && $args->walker->has_children ) ? ‘ </a><b class=”caret dropdown-toggle” … Read more

Automatically going to the first page in a hierarchy?

Referencing the wp_list_pages function reference You’ll probably need to use the second structure you listed, with one change: -Cars (shows a submenu with a list of cars, ie Volvo 850, Porsche 911 ) -Volvo 850 overview (the page you get when you click Volvo 850 on the Car page) -Volvo 850 tech spec (the three … Read more

Thesis -style Navigation

This is how I do it in a custom theme: <h3>Select pages to include in menu:</h3> <p> <?php $page_ids = get_all_page_ids(); $current_selected = get_option(“pages_to_include”); foreach( $page_ids as $page_id ) { if( get_post_status( $page_id ) == ‘publish’ ) { $checked = ( !empty( $current_selected ) && in_array( $page_id, $current_selected ) ) ? ‘ checked=”checked”‘ : ”; … Read more

Three menus – parent / child / sibling

To list top level pages only: wp_list_pages( ‘depth=1’ ); To list children of the current page, but only if it is a top level page: if ( 0 == $post->post_parent) { wp_list_pages( ‘child_of=” . $post->ID . “&depth=1’ ); } To list children of the current page, but only if it is a child page: if … Read more