You could set the 'depth'
argument to 1
in your wp_nav_menu()
call to get only top level items, along with the custom menu walker, something like this:
return wp_nav_menu( array( 'menu' => $name, 'menu_class' => 'footer-menu', 'echo' => false, 'depth' => 1, 'walker' => new custom_footer_menu_walker ) );
Add the custom menu walker to your functions.php (12345 is the ID of your homepage, that should be excluded):
class custom_footer_menu_walker extends Walker_Nav_Menu {
function start_el( &$output, $item, $depth = 0, $args = array(), $id = 0 ) {
parent::start_el($item_html, $item, $depth, $args);
$exclude = array();
$exclude[] = 12345;
if ( ! in_array( $item->object_id, $exclude ) ) {
$output .= $item_html;
}
}
}
Related Posts:
- Return only top-level navigation items from a menu using wp_get_nav_menu_items
- Is there a way to add a class to non current menu item?
- Why does the ‘wp_nav_menu’ function work only until a menu is created?
- Nav menus all outputting the same links
- wp_nav_menu work in functions.php but not in the theme
- wp_nav_walker that interacts with widgets to setup mega menu
- Why don’t ‘wp_nav_menu’ CSS classes work until a menu is created?
- Issues with title-tag and document_title_parts
- Get menu object from theme_location
- Is it ok to use a function to output the text domain name in a wordpress theme
- TinyMCE custom styles remove class when switching styles
- Using wp_get_nav_menu_items() to list children of children pages
- Breadcrumbs showing Parent and Child Pages
- Show/hide Widgets in Dashboard Based on Current Advanced Custom Fields Option
- Custom menus displaying all pages instead of set pages
- Overriding core functions in child theme
- Dynamically add sub-categories to any category in the menu
- Change parent theme file function in child themes functions.php
- Two different menus for two different locations?
- Dequeue Scripts and Style for Mobile not working?
- Unregister Nav Menu with fallback?
- Displaying Widgets
- Editing or filtering the output of the Genesis navigation
- Best Practice for Syncing Local Development With Staging Development [closed]
- Overwrite Parent Theme add_image_size in Child Theme
- Show excerpt for only first post in query
- How to add css class to image attached in all the posts?
- When using wp_enqueue_script(); in a theme why don’t we use add_action?
- CSS for menu item added via functions.php
- How To Remove Duplicate Menu Locations
- How to use Internationalized human_time_diff() function in Chinese?
- is_dynamic_sidebar always returns true while using Jetpack visibility
- Where do I add html code to the menu div?
- Replace menu links with # and add name to its li
- How do I create page navigation linking to each H2 within the page? [closed]
- Function issue with Walker_Nav_Menu [duplicate]
- Custom Static Links For Specific Menu Right Before/Next The wp_nav_menu Function now working
- Add caption functionality to custom WordPress theme
- Override a theme function in a child theme?
- Make parent page only link to first subpage
- Pulling Twitter RSS feed not working as expected (fatal error)
- wp_nav_menu, walker class, categories as classes of li
- Use register_setting() in a loop
- Best practices regarding the creation of custom widgets?
- Add dynamic links in WordPress custom theme
- WordPress menu link doesn’t work properly
- Search filter by Post title OR Meta Title Value [duplicate]
- Custom Nav Walker sub-menu
- admin-ajax.php + load-scripts.php hanging for minutes
- Replace a menu with widget or a custom template file programmatically
- Unique sequential reservation code
- Functions.php Problem
- How to customize the_archive_title()? Cannot figure out how to change the value it produces [duplicate]
- Control the srcset much more (not all sizes in it each time)
- Way to store featured image width and height in two separate variables?
- Excerpt for pages not showing
- Some questions about how proper add 2 CSS file in a WordPress theme?
- Dropline menus — seperators between children only?
- retrieves menu and converts it to a readable array
- Default Nav Highlight
- why is this function firing on all child menu items as well?
- WP Customizer API loaded into functions.php
- call_user_func_array() expects parameter 1 to be a valid callback, function
- why can’t i add front.css to my frontpage.php
- Different methods of adding menu support to custom theme
- “options.php” not found
- How to add aria role and schema markup to custom walker container
- Multiple navigation menu in same location
- How to hightlight all ancestor menu items of a child page NOT displayed in menu
- contact form in template with jquery,validate and ajax
- current_page_item is missing inside wp_nav_menu
- Why a SlideShow (made using JQuery FlexSlider) can’t work if I load it form functions.php but work if I load it from my footer.php file? [closed]
- Why I can’t load my JavaScripts using an hook inside my functions.php file?
- How Can I add a menu to the theme from withen the function.php file
- define css class in functions.php
- How would I make a function to dynamically determine if user is logged to change navigation menu text?
- Woocommerce Variable Product Dropdown for Custom Shop Template
- Exclude specific post from query
- Advanced method to control cache of enqueued style/script
- Bizarre Child Menu Issue on WP Site
- Header menu aligned right on all pages except for single-post page [closed]
- Is_Page doesnt detect my page
- Test CDN link from function.php or wp_enqueue_script/style?
- How to customize archive widget only for cpt?
- How to automatically add counted number to navigation menu items?
- Why does echo on functions.php not yield result in source code?
- Combine multiple menus using the filter wp_nav_menu_items
- WordPress Toggle Menu has stopped working
- Add meta data in head from theme
- what is `get_section()` and how to use it?
- Remove External Links from WordPress posts Using add_filter() in Theme functions.php
- How to add widget in main menu
- Insert menu into theme location depending on user logged in/out status
- Allow tags and attributes in post and pages content
- How do I get my nav menu to show sub pages?
- Notice: Use of undefined constant REQUEST_URI – assumed ‘REQUEST_URI’ in ….functions.php on line 73
- Why functions metaboxes is causing White Screen in Admin [closed]
- Getting error on function.php
- How to add more than one menu for logged in members?
- Setcookie not setting cookies anywhere except admin