How to remove logout confirmation message in WordPress

A logout confirmation message such as  "You are attempting to log out of ... Do you really want to log out?" might appear sometimes when you click on the "Logout" menu item in WordPress.

Logout Confirmation message in WordPress

This message is displayed because the logout process is not complete properly.

In this case, instead of adding a "Logout" menu in "Appearance > Menu" in Dashboard, you can try to add the following function to your WordPress theme function file (functions.php):

add_filter( 'wp_nav_menu_items', 'add_loginout_link', 10, 2 );
function add_loginout_link( $items, $args ) {
if (is_user_logged_in() && $args->theme_location == 'primary') {
$items .= '<li><a href="'. wp_logout_url( home_url() ) .'">Logout</a></li>';
}
return $items;
}

where the part "theme_location" should be changed according to the actual menu location of your theme's navigation menu. Please refer to here for wp_logout_url().

Now, you will be redirected to homepage when you click on "Logout". If you want to redirect to current page, please replace wp_logout_url( home_url() ) with wp_logout_url( get_permalink() ).


Leave a Comment