Logout redirect to current page – function

Using this code in the functions.php does the trick:

function wpse_44020_logout_redirect( $logouturl, $redir )
{
    return $logouturl . '&redirect_to=' . get_permalink();
}
add_filter( 'logout_url', 'wpse_44020_logout_redirect', 10, 2 );

Note – The above code works only on non-admin pages. To make this work on any page you should replace:

return $logouturl . '&redirect_to=' . get_permalink();

With:

return $logouturl . '&redirect_to=http://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];

Leave a Comment

error code: 523