How do you create a WordPress menu logout link that bypasses the "are you sure you want to log out" message?

0
0

This is what worked for me.  First I created a custom log out menu link like the one below.  I named the link label “logout”

https://yoursite.com/wp-login.php?action=logout&redirect_to=https://yoursite.com

Then

I added the code below to my child theme’s functions.php file:

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');

The above code adds the variable necessary to disable the message to the link labeled “logout”

Source: https://wordpress.stackexchange.com/questions/274257/using-nonce-in-menu-item

  • You must to post comments
Showing 1 result
Your Answer
Post as a guest by filling out the fields below or if you already have an account.
Name*
E-mail*
Website