I triy to add a ‘logout’ button on the main nav menu under ‘account’ parent menu. But, the button does not rendor.
At Appearance > Menus, I add ‘account’ page to the active menu. (link enabled) I add a code snippet The code here;
function my_insert_primary_nav_login_link( $items, $menu, $args ) { if( is_admin() ) return $items; // Bail out if this menu isn't main-menu or Main Menu is being loaded in the dashboard. if( $menu->slug !== 'main-menu' || is_admin() ) return $items; // Find the ID of the Page with the slug account in the menu items. foreach( $items as $item ) { if( $item->post_type !== 'page' || $item->post_name !== 'account' ) continue; $account_page_id = $item->ID; break; } // Bail if the account page is not in this menu. if( ! isset( $account_page_id ) ) return $items; $logged_in = is_user_logged_in(); $link_title = __( $logged_in ? 'Log In' : 'Log Out', 'oceanwp' ); // Insert a new WP_Post object for the link. $items[] = new WP_Post( (object) [ 'ID' => 'user-login', 'menu_item_parent' => $account_page_id, 'classes' => [ 'account-auth-link' ], 'type' => 'virtual', 'object' => 'virtual', 'title' => $link_title, 'attr_title' => $link_title, 'url' => $logged_in ? wp_logout_url() : wp_login_url(), ] ); return $items; } add_filter( 'wp_get_nav_menu_items', 'my_insert_primary_nav_login_link', 10, 3 ); I use OceanWP theme. I checked that the function fires and menu slug is main-menu but for some reason, it seemingly does not append 'account'parent menu.
If you could share your idea, I would much appreciated.



$itemsand edit your question to show us the result.