Actually, it is working – it just doesn’t do what you think it does.
The v_forcelogin_redirect filter is for specifying where the user is sent (redirected) to after they log in; it does not change the URL of the login page.
It dont work, Iam redirected to http://mydomain/wp-login.php?redirect_to=http%3A%2F%2Fmydomain%2Flogon%2F
In your code, you set the v_forcelogin_redirect filter to redirect visitors to: site_url( ‘/logon/’ ); after they login. And as you’ve pointed out, the login page shows the ?redirect_to= query string to point to that exact URL.
I assume you were trying to change what WordPress considers your login page URL to be? If so, try the following code instead:
// Custom Login URL
function my_login_page( $login_url, $redirect ) {
return site_url( '/logon/' );
}
add_filter( 'login_url', 'my_login_page', 10, 2 );
Thanks so much! Now the redirect to different login URL work, but after login (i change that first code to /info/ so that it redirect me to mydomain/info/ after I log in but Iam still on the same page after logging in 🙁
When you go to log in, does the URL have the ?redirect_to= query string? If not, that is why you aren’t being redirected to /info/ after login.
I suspect the issue is you’re going directly to the login URL without typing the ?redirect_to= query string.
If you want to ensure visitors are always redirected after login, try adding the following code directly below your v_forcelogin_redirect filter:
add_filter('login_redirect', 'my_forcelogin_redirect', 10, 1);