You could use something like this:
// Function to hide menu items for non-logged-in users
function hide_menu_items_for_non_logged_in($items, $args) {
// Check if user is not logged in
if (!is_user_logged_in()) {
// Define menu items to hide
// (replace 'menu-item-1', 'menu-item-2', etc. with actual menu item IDs)
$items_to_hide = array('menu-item-1', 'menu-item-2');
// Loop through menu items
foreach ($items as $key => $item) {
// Check if the current item is in the list of items to hide
if (in_array($item->ID, $items_to_hide)) {
// Remove the item from the menu
unset($items[$key]);
}
}
}
return $items;
}
// Hook the function into the 'wp_nav_menu_items' filter
add_filter('wp_nav_menu_items', 'hide_menu_items_for_non_logged_in', 10, 2);
You could also use a CSS class that turns off display for specific items in the above loop; something like:
if (in_array('hide-for-non-logged-in', $item->classes)) {
// Add a custom CSS class to the item
$item->classes[] = 'hide-item';
}
Then adding that ‘hide-item’ CSS to your ‘Additional CSS’.