Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I would like to redirect this page wp-login.php to /login page. So when a user clicks on a link like this <a href="/wp-login.php">login</a>, wordpress will redirect him to /register .

I found this function and modified it :

add_action('init','custom_login');

function custom_login(){
 global $pagenow;
 if (( 'wp-login.php' == $pagenow ) && (!is_user_logged_in())) {
  wp_redirect('/login');
  exit();
 }

I am not good with wordpress coding.

The redirection works fine, but the authentication seems to be broken. When I enter my login/pass, the same page (/login) reloads without being authenticated.

Any suggestion to fix the function for redirection ?

share|improve this question
    
what you want is a custom login page, you can find numerous tutorial on how to do it, and about stopping the redirection of custom login page to wp-login.php the following Link might help. –  Maruti Mohanty Jan 7 at 11:17

2 Answers 2

If you will create a custom login page on your address /login, then create a rewrite:

function restrict_admin() {

    if ( ! current_user_can( 'manage_options' ) && '/wp-admin/admin-ajax.php' != $_SERVER['PHP_SELF'] ) {
                wp_redirect( site_url() );
    }
}
add_action( 'admin_init', 'restrict_admin', 1 );

This code will check if the user is an administrator and if they are not WordPress will redirect them back to the website home page.

Create also a side template for your custom login and use the login defaults of WordPress inside the template:

$args = array( 'redirect' => site_url( $_SERVER['REQUEST_URI'] ) );
wp_login_form( $args );

You can also change the redirect adress for the login page. But is also useful, that you check on login errors and maybe you add code for right redirect after failed login. For this jobs use the hook wp_login_failed and authenticate.

share|improve this answer

1. Modify your .htaccess file – add this line after index.php rewrite rule:

RewriteRule ^index\.php$ – [L]<br />
RewriteRule ^yoursecretpath$ wp-login.php [L,NC,QSA]

where yoursecretpath is your path to admin panel.

2. Modify login_header function in wp-login.php file – add this code just before line 59 (where HTML doc type tag starts, so to prevent headers sending error):

<?php $uri = $_SERVER['REQUEST_URI']; if(stripos($uri, ‘wp-login’) or stripos($uri, ‘wp-admin’) && !stripos($GLOBALS["HTTP_COOKIE"], ‘wordpress_logged_in’)) {  header("Location: ".get_site_url().'/yoursecretpath' ); exit(); } ?>
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.