When I created the navigation menu at the top of my site using the menu feature in WordPress (Appearance → Menus), I didn’t want to have to maintain anything but the top-level menu items. When I released a new plugin and created a page for it, I didn’t want to have to go into my menu UI and add it there too. So instead I wrote this plugin.
Add Descendants As Submenu Items adds a checkbox to each menu item that is of a hierarchical post type (i.e. pages) or taxonomy (i.e. categories). Checking this box will automatically display all descendants as submenu items on the front end of your site. You can see it in action at the top of my site — I only configured the top level menu items and everything that shows up when you hover over them has been added by my plugin rather than manually by me.
Download:
- Download from WordPress.org (0 downloads)
Screenshots:
- An example menu and the checkbox this plugin adds
- These submenu items have been added by the plugin
Alex, is it possible to specify a limit for the depth of the children? For example, I want to add only direct children to the menu item but not also children of these children.
Hi Hassan, I have requested this feature also! I have posted a short tutorial on how to tweak the code to make it only add direct children on http://cladlab.com/programming/website-design/wordpress/wordpress-plugins-that-this-site-uses
The page linked above is gone but I found the code using archive.org. Here it is for others.
Find this section:
case ‘post_type’:
// Using get_pages() instead of get_posts() because we want ALL descendants
$children = get_pages( array(
‘child_of’ => $item->object_id,
‘post_type’ => $item->object,
‘sort_column’ => ‘menu_order, post_title’,
) );
and change to:
case ‘post_type’:
// Using get_pages() instead of get_posts() because we want ALL descendants
/* Edit by gbmhunter to remove grandchildren. Removed the following
$children = get_pages( array(
‘child_of’ => $item->object_id,
‘post_type’ => $item->object,
‘sort_column’ => ‘menu_order, post_title’,
) );
*/
/* And added this */
$children = get_pages(‘child_of=’.$item->object_id.’&parent=’.$item->object_id);
Hello scalewoo,
Is the code still working for you?
Thank you
Great plugin, Alex. I wasn’t sure at first whether each parent item could have submenus enabled separately, but a quick play with the plugin confirmed this feature. One less thing for the less technically-minded person who updates the site to have to worry about!
Pingback: Using Categories in Navigation Menu for WordPress
Hi Alex, thank you very much, you’ve saved me a ton of work. I’ve rated the plugin 5 stars at wordpress.org where there is a message ‘This plugin hasn’t been updated in over 2 years.’ etc. I have it working on the current WordPress 3.9.2 using Uber menu 3. so it is working. Perhaps you can change the date of the plugin or something to remove the message.
I have spent many hours searching for a way to automatically add child or sub categories to a top menu item in wordpress. I believe this is the only plugin that will do that.
thanks again
Rob
Yeah, I need to go through all my plugins and bump their “tested up to” version numbers. I write my plugins well the first time around so I rarely need to update them — they just continue to work fine with new versions of WordPress. 🙂
Glad you like the plugin!
Just thanking you. =)
Nice works great for regular categories… Any chance i could get it to work with QWoocommerce Product Categoies? I tried and it doesnt seem to work with it
It should work for any hierarchical taxonomy, i.e. any taxonomy that can have parents and children. If it’s not hierarchical, then it won’t work with my plugin.
Strange ya I just tried and it doesnt seem to work with my woocommerce sub menus do you think you could login mayeb and see Im in no way a WordPress Expert yet lol Im more uh CS-Cart guy but moved to woo mainly due to it having great plugin support liek YOUR! ha
I have installed your plugin, however when I click Automatically add all descendants as submenu items in Appearance-Menus , I do not get all my descendant children subcategory items shown when I hover over the main menu. Do you know why?
Pingback: My Favorite WordPress Plugins | cmarabate.com
Pingback: My Favorite WordPress Plugins | Bonkage.com
Pingback: My Favorite WordPress Plugins - Chris Marabate's BlogChris Marabate's Blog
Pingback: The Best WordPress Plugins – WordPress Site Handbook
Hi, what a great plugin!
How can you hide empty subcategories, that is, they have no items in stock?
Currently shows all subcategories associated with a category.
Thank you.
That would make more sense I think, and I believe it’s the default behavior for most places in WordPress. I’ll try to take a look when I have a chance in a few weeks.
Hi Alex, have you ever gotten around this request please ? It would be so great if only categories with products availables would be displayed in the menu 😀 Thanks in advance for your response 😉 Bye
I love this plugin, thank you so much! The only issue that I’ve found with it, is that when it is enabled, I get the following error message at the top of the customizer (appearance > customize):
Fatal error: Uncaught Exception: Supplied nav_menu_item value missing property: status in /home/publicr2/public_html/wordpress/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php:183 Stack trace: #0 /home/publicr2/public_html/wordpress/wp-includes/class-wp-customize-nav-menus.php(692): WP_Customize_Nav_Menu_Item_Setting->__construct(Object(WP_Customize_Manager), ‘nav_menu_item[2…’, Array) #1 /home/publicr2/public_html/wordpress/wp-includes/class-wp-hook.php(286): WP_Customize_Nav_Menus->customize_register(Object(WP_Customize_Manager)) #2 /home/publicr2/public_html/wordpress/wp-includes/class-wp-hook.php(310): WP_Hook->apply_filters(NULL, Array) #3 /home/publicr2/public_html/wordpress/wp-includes/plugin.php(453): WP_Hook->do_action(Array) #4 /home/publicr2/public_html/wordpress/wp-includes/class-wp-customize-manager.php(926): do_action(‘customize_regis…’, Object(WP_Customize_Manager)) #5 /home/publicr2/public_html/wordpress/wp-includes/class-wp-hook.php(286): WP_Customize_Manager->wp_loaded(”) #6 /home/ in /home/publicr2/public_html/wordpress/wp-includes/customize/class-wp-customize-nav-menu-item-setting.php on line 183
Any ideas what may be going on?
Thanks very much,
Matt
I can’t reproduce this on my test site which means I can’t debug it to figure out what’s going wrong. 🙁
Does it still happen if you temporarily disable all plugins except mine?
If it does still happen, shoot me an email and we can continue from there: https://alex.blog/contact/
Exactly th same error for me. I installed the plugin on a new wordpress installation with the twentysewenteen template.
The plugin works very well everywhere except when I open “appearance > customize”.
Do you have found a solution?
Thanx
Stan
I haven’t found a solution, unfortunately 🙁 I just disable it temporarily if I really need to use the customize/preview functionality… only workaround that seems to work for now :\
Hi. Thanx for your response.
Hopefully Alex will add a solution and update the plugin…
Hi Alex, great plugin, saved me lots of work. One question: is it possible to edit the names of the submenu items in the menu? thanks!
Nope, sorry. If you want manual control, you’ll have to manually create the menu.
Not sure if I missed a step while configuration this plugin. The sub categories of my main categories aren’t showing. Even though I checked “Automatically add all descendants as submenu items”. Advise anyone.
Would really like to use this plugin, but we need to limit the submenu to the children, and not display the grandchildren. I see someone linked to a tutorial above but the link is a dead page. Any other advice on code to add to remove grandchildren?
Hi there! Sadly the Plugin does not work, when using Woocommerce and the enfold theme. The Customizer will not load, only a 500 Error will appear.
Best wishes
Thanks for this great plugin. Very simple but very useful – especially when creating submenus based on taxonomies!
Anybody looking to fix the error 500 in the customizer:
edit add-descendants-as-submenu-items.php, go to line 293 (after the line that reads “$child->db_id = $child->ID;”) then add this code:
if (empty($child->status)) {
$child->status = ‘publish’;
}
That fixed it for me (WordPress 5.2.3).
Great stuff! I have just added this to my site and is working a treat! Thanks
A nice article. Thanks for sharing.
Thank you very much for this amazing post. I admire your inspiring and motivating works and I would love to read more of your great article.