How to Change wp-admin URL in WordPress Securely
To change the
wp-admin URL in WordPress, use a security plugin like WPS Hide Login that lets you set a custom login URL easily. Alternatively, you can add custom code to your functions.php file, but using a plugin is safer and simpler.Syntax
Changing the wp-admin URL is usually done by setting a new login slug that replaces the default /wp-admin or /wp-login.php path. This can be done via plugins or custom code.
- Plugin method: Configure the new login URL in the plugin settings.
- Code method: Use WordPress hooks to intercept login requests and redirect.
php
add_action('init', function() { $new_login_slug = 'my-login'; if (strpos($_SERVER['REQUEST_URI'], '/wp-login.php') !== false || strpos($_SERVER['REQUEST_URI'], '/wp-admin') !== false) { wp_redirect(site_url('/' . $new_login_slug)); exit; } });
Example
This example shows how to use the WPS Hide Login plugin to change the login URL to /my-login. It is the safest and easiest way without touching code.
wordpress
1. Install and activate the <strong>WPS Hide Login</strong> plugin from the WordPress plugin repository. 2. Go to <em>Settings > WPS Hide Login</em> in your WordPress dashboard. 3. Enter <code>my-login</code> in the <strong>Login URL</strong> field. 4. Save changes. Now, your login page is at <code>https://yourdomain.com/my-login</code> instead of <code>/wp-admin</code> or <code>/wp-login.php</code>.
Output
Accessing https://yourdomain.com/wp-admin or /wp-login.php will show a 404 error or redirect to the new login URL.
Common Pitfalls
Changing the wp-admin URL incorrectly can lock you out of your site or break admin access. Common mistakes include:
- Not backing up before changes.
- Using custom code without proper redirects.
- Forgetting the new login URL and losing access.
- Conflicts with other plugins or caching.
Always test changes on a staging site first and keep your new login URL saved safely.
php
/* Wrong way: Simply renaming wp-login.php file (will break WordPress login) */ /* Right way: Use a plugin or proper redirect code as shown in the Syntax section */
Quick Reference
Summary tips for changing wp-admin URL:
- Use trusted plugins like
WPS Hide Loginfor easy setup. - Do not rename core WordPress files manually.
- Backup your site before making changes.
- Clear caches after changing URLs.
- Keep your new login URL private and secure.
Key Takeaways
Use a plugin like WPS Hide Login to safely change the wp-admin URL without coding.
Never rename WordPress core files like wp-login.php manually to avoid breaking login.
Always back up your site before changing login URLs to prevent lockout.
Keep your new login URL secure and remember it to maintain admin access.
Test changes on a staging site and clear caches after updating the login URL.