Retrieving a list of menu items in an array
wp_get_nav_menu_items would appear to be exactly what you require. It returns an array of menu objects.
wp_get_nav_menu_items would appear to be exactly what you require. It returns an array of menu objects.
The function wp_nav_menu takes an argument of fallback_cb which is the name of the function to run if the menu doesn’t exist. so change you code to something like this: function wp_nav_menu_no_ul() { $options = array( ‘echo’ => false, ‘container’ => false, ‘theme_location’ => ‘primary’, ‘fallback_cb’=> ‘fall_back_menu’ ); $menu = wp_nav_menu($options); echo preg_replace(array( ‘#^<ul[^>]*>#’, ‘#</ul>$#’ … Read more
You can’t do this with wp_nav_menu, because it outputs list items, and you’ll generate invalid markup with your code. Try using wp_get_nav_menu_items() instead. A quick solution for a drop down menu with a custom walker: class Walker_Nav_Menu_Dropdown extends Walker_Nav_Menu{ // don’t output children opening tag (`<ul>`) public function start_lvl(&$output, $depth){} // don’t output children closing … Read more
I was also looking for a solution for this and I found simple one. This is what you need to place into the URL field: /index.php/internal-site-name It works just fine! Best Regards Chris
The wrapping div is easy. When you use wp_nav_menu(), add this argument: ‘container’ => false For the <ul> element, there’s an argument called ‘items_wrap’. See woodchucky’s answer for more info on that one (and upvote it!).
The Problem with your code is that its not actually adding the links to the menu and only to the menu’s output, hence the use of a filter (add_filter) so you are just filtering the output of the menu in fact even if you don’t have a menu your link will be shown with the … Read more
There is a navigation menu plugin extension for the REST API v2: https://wordpress.org/plugins/wp-api-menus/
start_el() should get this information in its $args parameter, but it appears WordPress only fills this in if $args is an array, while for the custom navigation menus it is an object. This is reported in a Trac ticket. But no problem, you can fill this in yourself, if you also override the display_element() method … Read more
OK, I found the answer to this one and its surprisingly simple but maddeningly frustrating at the same time. All you have to do is click “Screen Options” while viewing the “Custom Menu” manager and place a check beside “Posts” to show the elusive hidden “Posts” widget. Now you can add “Posts” to your custom … Read more
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