Enhancing Skills

Change my wp-admin to test-admin-url

Changing the wp-admin URL can improve the security of your WordPress site. By default, the wp-admin URL is a well-known and easily guessed location for attackers to try to access and exploit your site. Changing the URL makes it harder for attackers to find the login page, reducing the risk of brute-force attacks.

However, changing the wp-admin URL does not guarantee complete protection against attacks. It is just one of the measures to enhance your website’s security. Other security measures, such as using strong passwords, keeping plugins and themes up-to-date, and enabling two-factor authentication, should also be implemented to ensure maximum security.

Here is how you can change the wp-admin URL by updating the theme code in the following way:

  • Open your theme’s functions.php file.
  • Add the following code:
add_filter( 'site_url', 'custom_login_url', 10, 3 );
function custom_login_url( $url, $path, $orig_scheme ) {
    if ( 'wp-login.php' == $path || 'wp-admin' == $path || 'wp-login.php?action=register' == $path ) {
        $url = site_url( 'test-admin-url' );
    }
    return $url;
}

add_action( 'admin_init', 'custom_redirect_wpadmin' );
function custom_redirect_wpadmin() {
    $requested_url = $_SERVER['REQUEST_URI'];
    $admin_url = site_url( 'test-admin-url/' );
    if ( strpos( $requested_url, 'wp-admin' ) !== false && strpos( $requested_url, 'wp-admin/admin-ajax.php' ) === false && $requested_url != $admin_url ) {
        wp_redirect( $admin_url );
        exit;
    }
}
  • Replace 'test-admin-url' with the new URL that you want to use for your wp-admin.
  • Save the file.

This code will change the wp-admin URL to the new URL that you specified. Note that this will also change the URL of the login page and the registration page. Make sure to update any links or bookmarks to the old wp-admin URL.


Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.