Change Wordpress login URL

Back

Changing wp-login to something else in WordPress 3.7

A lot of the time people dislike having wp-login as their url to sign in. Why, I don't know, but they do. So if you're really dying to change the sign up url this is one way to do it:

Step 1. Change .htacess

You'll want to add something like this into your htaccess file:

RewriteBase /
RewriteRule ^sign-in$ wp-login.php

This will let your server know to respond to the url and send the information to the wp-login page when a request for sign-in comes by.

Step 2. Change output of wp_login_url

add_filter('login_url', 'wp_login_filterlink', 10,100);
function wp_login_filterlink($url, $redirect)
{
    $old  = array( "/(wp-login\.php)/");
     $new  = array( "sign-in");
     return preg_replace( $old, $new, $url, 1);    
}

Adding the above code to your functions.php will cause the link used when calling the wordpress function wp_login_url to use your new url instead of the old.

Step 3. Filter the output of site_url

add_filter('site_url',  'wplogin_filter', 10, 3);
function wplogin_filter( $url, $path, $orig_scheme )
{
     $old  = array( "/(wp-login\.php)/");
     $new  = array( "sign-in");
     return preg_replace( $old, $new, $url, 1);
}

Once again, in functions.php add the code above. This will help you out whenever the login url is generated by the site_url function. It's important to filter both site_url and wp_login_url so that you don't accidently end up linking to wp-login, while it won't hurt you to do so, if your goal is to change the URL then you want to cover all your bases.

Some notes

Even though you're using a new URL, your old wp-login.php address will still work. So if you're changing the URL for anything other than aesthetic reasons, you might want to look into plugins for your security needs.

Other Posts

comments powered by Disqus