@jurasjo ‘s code didnt work for me but @caleb ‘s did.
To redirect I just added “&redirect_to=logout”
“logout” is the name of the page (the permalink/url) I wanted to redirect to in my case but you can use anything in there.
Final URL that I added to the menu via Custom Link with “Logout” label was:
https://yourdomain.com/wp-login.php?action=logout&redirect_to=logout
With this code:
function change_menu($items){
foreach($items as $item){
if( $item->title == "Logout"){
$item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' );
}
}
return $items;
}
add_filter('wp_nav_menu_objects', 'change_menu');