Try below Code is that works
Note : Replace $pageid with the page you want users to be redirected to
/* Redirect log in page */
function redirect_login_page(){
// Store for checking if this page equals wp-login.php
$page_viewed = basename( $_SERVER['REQUEST_URI'] );
// permalink to the custom login page
$login_page = get_permalink($pageid);
if( $page_viewed == "wp-login.php" ) {
wp_redirect( $login_page );
exit();
}
}
add_action( 'init','redirect_login_page' );
Let us know if this works.
Thanks.
]]>Thanks for your reply.
Main problem is the if condition here. page_viewed does not match wp-login.php. When we enter URL – sitename/wp-admin it redirects to {sitename}/wp-login.php?redirect_to=http%3A%2F%2Flocalhost%2F{siename}%2Fwp-admin%2F&reauth=1
which is not equal to “wp-login.php”
I hope what I am saying makes sense.
]]>Yes, I understand your concern, but I did try this code in my Local Env and it worked fine for me.
I think you should check what value you get in $page_viewed by printing it, that will give you more clarity on what your if condition will be.
Hope this helps.
Thanks.
]]>