Вот должно работать.
add_filter( 'login_redirect', 'my_login_redirect', 10, 3 );
add_filter( 'logout_redirect', 'my_logout_redirect_filter', 10, 3 );
/**
* Function for <code>login_redirect</code> filter-hook.
*
* @param string $redirect_to The redirect destination URL.
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
* @param WP_User|WP_Error $user WP_User object if login was successful, WP_Error object otherwise.
*
* @return string
*/
function my_login_redirect( $redirect_to, $requested_redirect_to, $user ) {
if ( ! $requested_redirect_to ) {
$redirect_to = wp_get_referer();
}
return $redirect_to;
}
/**
* Function for <code>logout_redirect</code> filter-hook.
*
* @param string $redirect_to The redirect destination URL.
* @param string $requested_redirect_to The requested redirect destination URL passed as a parameter.
* @param WP_User $user The WP_User object for the user that's logging out.
*
* @return string
*/
function my_logout_redirect_filter( $redirect_to, $requested_redirect_to, $user ){
if ( ! $requested_redirect_to ) {
$redirect_to = wp_get_referer();
}
return $redirect_to;
}