I am making a Logout button, but in order for it to work properly the link needs to have the correct nonce ("site.com/wp-login.php?action=logout&wp_nonce=X". I have found in another question (How to log out without confirmation 'Do you really want to log out?"?) a way to add the nonce, but it is only for menu links:
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');
How can I do the same for a button?