Not showing Custom 404 error page
-
Hi
Thank you for the plugin. It’s really very great.
I have a question, when I key in http://example.com/wp-login.php, it shows a 404 error page, but is not my custom 404 error page. So is there a way to change it ?
Thanks.
-
It should show your theme’s 404 page. Is that not the case?
No, it is not showing my custom 404 error page. However, I have resolved it by adding a code to this functions.php.
Thanks a lot.
What did you add to functions.php? By custom 404 page, do you mean 404.php in your theme, or something else?
I added in this code :
add_action('init','custom_login'); function custom_login(){ global $pagenow; if( 'wp-login.php' == $pagenow ) { wp_redirect('home url(), 404'); exit(); } }[Moderator Note: Please post code & markup between backticks or use the code button. Your posted code may now have been permanently damaged by the forum’s parser.]
I have created a 404.html page so I am not using any 404.php at all.
Thanks.
Why not add the wp_redirect() to a 404.php?
Or add this in your functions.php:if ( is_404() ) { wp_redirect( ... ); die; }wp-login.php is not going to have ‘wp-login.php’ == $pagenow since it makes it look like that page doesn’t exist.
Since wp-login.php “doesn’t exist”, is_404() will be true.
Sorry, I do not know where to insert this line:
if ( is_404() ) { wp_redirect( … ); die; }
Thanks.
In your functions.php file or in a custom plugin… You’ll need to replace the ‘…’ with the path to your custom 404.html.
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.
Try this, assuming 404.html and the php file you’re adding this to are in the same directory.
add_action( 'init', 'custom_login' ); function custom_login() { if ( is_404() ) { wp_redirect( '404.html' ); die; } }Sorry, wp_redirect needs a URL, not a path, so:
add_action( 'init', 'custom_login' ); function custom_login() { if ( is_404() ) { wp_redirect( home_url( '/404.html' ) ); die; } }So far thank you very much.
I notice that once I added in the above code, the visitor (eg. subsciber) unable to log in or register from my site as it shows 404 page.
So I change to use 404.php which I have just created and remove the above code (functions.php).
Let says I rename wp-login.php as login2. When I enter xxx.com/wp-login.php, it shows me 404.php, that is good to me. However, I act as a visitor tries to log in and register to my site, it shows me xxx.com/login2, in which the visitor will know this is my new wp-login.php.
Normally, when visitor tries to login, it points to xxx.com/login, instead of xxx.com/login2 and register, it will point to xxx.com/register, but why is xxx.com/login2 again ?
So I am wondering what is going wrong ? Is there anything to do with this plugin ?
Thanks.
The topic ‘Not showing Custom 404 error page’ is closed to new replies.