How do I check if a menu exists?

Assuming that you have custom Nav Menus implemented properly: Registering nav menu Theme Locations: register_nav_menus( array( ‘parent_page’ => “Parent Page”, ‘page_a’ => “Page A”, ‘page_b’ => “Page B”, //etc ) ); Calling wp_nav_menu() correctly: wp_nav_menu( array( ‘theme_location’ => ‘page_a’ ); …then you can use the has_nav_menu() conditional to determine if a Theme Location has a … Read more

wp_nav_menu always falls back to a menu

wp_nav_menu() indeed tries a lot to provide you with a menu, and fallback_cb is only executed when nothing else works. From the code: If menu is provided and refers to an existing menu (looked up via wp_get_nav_menu_object(), which accepts an id, slug or name), this will be the menu Otherwise, if theme_location is set to … Read more

Add a .last class to the last in each ul.sub-menu

Put the following in your functions.php class SH_Last_Walker extends Walker_Nav_Menu{ function display_element( $element, &$children_elements, $max_depth, $depth=0, $args, &$output ) { $id_field = $this->db_fields[‘id’]; //If the current element has children, add class ‘sub-menu’ if( isset($children_elements[$element->$id_field]) ) { $classes = empty( $element->classes ) ? array() : (array) $element->classes; $classes[] = ‘has-sub-menu’; $element->classes =$classes; } // We don’t … Read more

add span class inside wp_nav_menu link anchor tag

Have you tried using the before or link_before parameters in your array arguments when declaring your wp_nav_menu function? Note: use after or link_after for the opposite effect. Example, wp_nav_menu( //normal arguments here….etc ‘before’ => ‘<span class=”arrow”></span>’, //or ‘link_before’ => ‘<span class=”arrow”></span>’, ); From the Codex: $before (string) (optional) Output text before the of the link … Read more

Pulling Featured Images in to a WordPress Menu

You can do that by filtering the menu objects using wp_nav_menu_objects filter. The following example will replace all titles of the menu items pointing to posts or pages with an <img> tag of the post or page thumbnail if available. It will target a menu with a name of Posts Menu called in theme using … Read more

How to add ul class on nav

It’s simple just you need to add items_wrap parameter and add or edit class attr: wp_nav_menu( array( ‘theme_location’ => ‘top-menu’, ‘container’ => false, ‘items_wrap’ => ‘<ul class=”nav your_custom_class”>%3$s</ul>’, ));