How to progmatically inject a submenu under a menu item created by this plugin?
-
I have some tried and tested code that I’ve used in the past to progmatically add a submenu item to a WP generated menu. This worked fine always. However using it with menus created by this plugin doesn’t work. I’ve made sure that I’m inserting the correct ID as a parent (menu_item_parent param) but it doesn’t help.
I’ve also tried changing the priority when I call my add_filter() but that also doesn’t seem to help. Any ideas?
// add a sub menu dynamically via code! function aj_add_menu_item( $items, $args ) { // check we are in the right menu if( $args -> theme_location =="primary" ) { $new_links = array(); // Create a nav_menu_item $newItem = array( 'title' => "Offers", 'menu_item_parent' => 71, 'ID' => 'loginout', 'db_id' => '12312332', 'url' => "offers", 'classes' => array( 'menu-item' ) ); $items[] = (object) $newItem; // add to end of existing object. menu_item_parent value will ensure it goes in right place return $items; }else{ return $items; } } add_filter( 'wp_nav_menu_objects', 'aj_add_menu_item', 10, 2 );
- This topic was modified 6 years, 5 months ago by .
- The topic ‘How to progmatically inject a submenu under a menu item created by this plugin?’ is closed to new replies.