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