I have a log out link in the main header menu, when you click on the link to log out, you are redirected to the page asking if you really want to log out. I know it's doing this because there is no nonce in the menu URL.

My question is: is it even possible to add a nonce in CMS appearance>menus in the edit menus screen? The url is something like: example.com/wp-login.php?action=logout&redirect_to=http://example.com/myaccount/&_wpnonce=

Just for giggles I tried adding wp_create_nonce('logout') to the end but of course it doesn't' work.

If this isn't possible is there another way to bypass the 'are you sure you want to log out' screen?

1 Answer 1


Just add a filter:

function change_menu($items){
  foreach($items as $item){
    if( $item->title == "Log Out"){
         $item->url = $item->url . "&_wpnonce=" . wp_create_nonce( 'log-out' );
  return $items;

add_filter('wp_nav_menu_objects', 'change_menu');
  • This works for me!
    – Strategist
    May 30, 2018 at 8:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.