Change Default WordPress Login URL within 2 lines of Code?
Tags: wordpress, development, beginners, tutorial
Published: 2023-09-14 06:02:49

As a WordPress user, you may be aware that the default login page URL for your website is something like `www.yourwebsite.com/wp-admin`. While this is convenient for most users, it can also make your website an easy target for hackers or malicious bots.

In this blog post, I will guide you through the process of changing the default WordPress login URL to something more unique and secure. By doing so, you can add an extra layer of protection to your website and reduce the risk of unauthorized access.

> **Recommended Plugin:** WP Adminify can help you to personalize your WordPress Dashboard, Change Login URL, Modify Admin Menu, and much more. Check More: [https://wpadminify.com/](https://wpadminify.com/?utm_medium=dev_to&utm_source=dev_posts)

I understand that not everyone is a coding expert, so don't worry - I will break down the steps into simple and easy-to-follow instructions. 

Whether you're a beginner or an experienced WordPress user, this guide will provide you with all the information you need to change your login URL without any hassle.

So, if you're ready to enhance the security of your WordPress website and learn how to change the default login URL using code, let's dive right in!

## Step 1: Backup Your Website

Before making any changes to your WordPress site, it's crucial to create a backup. This ensures that you can revert to the previous state in case anything goes wrong during the process. You can use a plugin like UpdraftPlus or manually back up your website files and database.

## Step 2: Access Your Website's Files

To change the default WordPress login URL, you need to modify your website's files. There are two ways to access these files: through an `FTP client` or using the `File Manager tool `in your hosting account's control panel. Choose the method that suits you best.

## Step 3: Locate Your `Theme's functions.php File`

Once you have accessed your website's files, navigate to the theme folder that is currently active on your WordPress site. Look for the `functions.php` file within that folder.

## Step 4: Edit `functions.php File`
Inside your theme's functions.php file or your custom plugin file, add the following code to perform the login URL redirection:

```
function custom_login_url_redirect() {
    // Check if the current request is for the login page
    if (strpos($_SERVER['REQUEST_URI'], '/wp-login.php') !== false) {
        // Redirect to the custom login URL
        wp_redirect('https://example.com/custom-login');
        exit;
    }
}
add_action('init', 'custom_login_url_redirect');
```

Replace `https://example.com/custom-login` with your actual custom login URL.

## Step 5: Test the New Login URL

Once you have saved the function.php file, you can test the new login URL by visiting your custom login page. Simply type in your newly specified URL in the browser's address bar and hit Enter. If everything is set up correctly, you should be redirected to the WordPress login page.

## Change Login URL using WP Adminify

Now I will walk you through the process of changing the default WordPress login URL using the [WP Adminify plugin](https://wordpress.org/plugins/adminify/). 

After installing WP Adminify Plugin navigate to [Redirect URL's module](https://wpadminify.com/modules/redirect-URLs/) options panel. Just type your new WordPress Dashboard login URL text and save. 


![New WordPress Dashboard Login URL Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4vk1y61vil2yuj15btkl.png)

Now let's test the Login URL. You can also redirect those users to a specific page who is trying to login by default WordPress login URL. 


![Custom WordPress Login URL](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6e6i5xqpwnorye4ridlc.png)

In conclusion, changing the default WordPress login URL using code can greatly enhance the security of your website. By implementing this simple yet effective technique, you can prevent unauthorized access and thwart potential attacks. I have discussed two methods - using a plugin and editing the functions.php file. Both methods are reliable and efficient, allowing you to choose the one that suits your preferences and expertise.

Remember, keeping your login URL hidden from prying eyes is just one step towards safeguarding your WordPress site. It is equally important to follow other security best practices such as using strong passwords, regularly updating plugins and themes, and implementing a reliable firewall.