I am using the following custom walker to hide the Login and Register pages from my navmenu created with wp_get_nav_menu_items…..
function wpse31748_exclude_menu_items( $items, $menu, $args ) {
// Iterate over the items to search and destroy
if ( is_user_logged_in() ) {
$registerpage = get_page_by_title( 'Register' );
$loginpage = get_page_by_title( 'Login' );
foreach ( $items as $key => $item ) {
if ( $item->object_id == $registerpage->ID ){
unset( $items[$key] );
}
elseif ( $item->object_id == $loginpage->ID ){
unset( $items[$key] );
}
else{}
}
return $items;
} else {
return $items;
}
}
add_filter( 'wp_get_nav_menu_items', 'wpse31748_exclude_menu_items', null, 3 );
It works fine but it is also affecting the menus page within the dashboard, is there a way to limit the crawler to only affect the front end?
You can try the
!is_admin()
so your code would be: