Logout redirect to current page – function

I’m looking for a function that can redirect users when they logout to the current page. I’m looking for a code I can use in functions.php?

4 s
4

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