Frankly, I have put that code for a test after I added in to functions.php :
[ Moderator Note: Please post code or markup snippets between backticks or use the code button. Or use pastebin.com instead. ]
add_action('init','custom_login');
function custom_login(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
wp_redirect('home url(), 404');
exit();
}
}
I notice that the visitor unable to register and login from my website. So I realise, I have missed out something but I do not know what is it.
As what you mention,
Since wp-login.php “doesn’t exist”, is_404() will be true.
if ( is_404() ) { wp_redirect( ... ); die; }
And needed to replace the ‘…’ with the path to my custom 404.html.
So I’m thinking that the code will be:
add_action('init','custom_login');
function custom_login(){
global $pagenow;
if( 'wp-login.php' == $pagenow ) {
wp_redirect('home url(), 404');
if ( is_404() ) { wp_redirect( '404.html' ); die; }
exit();
}
}
I have not given it for a test yet and I am not good in coding. Hope you don’t mind I am asking so much…
Thanks.