How to add sub menu item under specific menu?
-
Hello, I’m trying to add login/logout menu items as sub-items under specific menu (menu name is : author-menu)
My top menu item’s id is written as menu-item-7618 but I’m not sure how to write it I tried both but did not work.
Would you please check the code below?
It does not throw any error but does not do anything either.function add_menu_parent_class( $items ) { if( is_admin() || $args->theme_location != 'author-menu' ) return $items; $redirect = ( is_home() ) ? false : get_permalink(); if (is_user_logged_in() && $args->theme_location != 'author-menu') { $userdata = wp_get_current_user(); $link = '<a href="/sign-in" title="' . __( 'Login' ) .'">' . __( 'Login' ) . '</a>'; $link_profile = array ( 'title' => 'Logout', 'menu_item_parent' => 7618, 'ID' => '234234234234234', 'db_id' => '234234234234234', 'url' => $link, ); $items[] = (object) $link_profile; } else { $link = '<a href="' . wp_logout_url( $redirect ) . '" title="' . __( 'Logout' ) .'">' . __( 'Logout' ) . '</a>'; $link_logout = array ( 'title' => 'Login', 'menu_item_parent' => 7618, 'ID' => '5746734534', 'db_id' => '5746734534', 'url' => $link, ); $items[] = (object) $link_logout; } return $items; } add_filter( 'wp_nav_menu_objects', 'add_menu_parent_class',50,2 );
Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
- The topic ‘How to add sub menu item under specific menu?’ is closed to new replies.