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


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”


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”


  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.