I am building my website on Wordpress and I have created my custom login page.But for a post when an user comments and other nonlogged see the comment with along with a line down "Login to reply".And when the user clicks on that"Login" from "Login to reply" it redirects to wp-login.php.So how to redirect users to custom login page when "login to reply" for a post is clicked on wordpress instead of wp-login.php.
You need to redirect everytime WordPress looks for wp-login.php
.
You can do the same by using the below in your active theme's functions.php
file.
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( 'CUSTOM_LOGIN_PAGE_ID' );
if( $page_viewed == "wp-login.php" ) {
wp_redirect( $login_page );
exit();
}
}
add_action( 'init','redirect_login_page' );
-
thanks for your help. I have one thing to ask you. I have renamed wp-login.php with name wp-login.php plugin. So shall I use that renamed name in that code or wp-login? – user3187719 Jan 29 '14 at 7:21
-
Please never make changes to the core files, as you will loose all these changes on upgrade and
wp-login.php
is a core file – Maruti Mohanty Jan 29 '14 at 7:23 -
No I just did with a plugin. When I deactivates the plugin, it restores to normal. So please tell me what use renamed wp-login.php or wp-login.php. – user3187719 Jan 29 '14 at 7:27
-
I am not sure what you are saying, but the base line is you should try your best not to modify core files. – Maruti Mohanty Jan 29 '14 at 7:30
-
I am still not sure whats the confusion, you pasted the same code that i have put as the answer – Maruti Mohanty Jan 29 '14 at 7:38