Ankit Sudhera Portfolio Website

Programming and Support is my Quality
Programming and Support is my Quality
Programming and Support is my Quality

Forum

How to Change The W...
 
Notifications
Clear all

How to Change The WordPress Admin Login URL Without Plugin

1 Posts
1 Users
0 Reactions
324 Views
(@ankitbnl406)
Member Admin
Joined: 2 years ago
Posts: 6
Topic starter  

There are many methods, but I will mention few as below:

First Method (Redirect using site cookie, function and htaccess):

  1. Add below constants to wp-config.php file:
    define('WP_ADMIN_DIR', 'secret-folder');
    define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);

     

  2. Add below snippet in function.php file of your active theme

    add_filter('site_url', 'wpadmin_filter', 10, 3);
    function wpadmin_filter( $url, $path, $orig_scheme ) {
        $old = array( "/(wp-admin)/");
        $admin_dir = WP_ADMIN_DIR;
           $new = array($admin_dir);
        return preg_replace( $old, $new, $url, 1);
    }

  3. Add below lines to .htaccess file

    RewriteRule ^secret-folder/(.*) wp-admin/$1?%{QUERY_STRING} [L]

 

Second Method (Rename wp-login with new file like new-secret-login-file):

  1. Rename wp-login.php with new file like new-secret-login-file.php in the root admin folder.
  2. Open the new-secret-login-file.php and find and replace every instance of "wp-login.php" in the file – then replace it with your new file name as new-secret-login-file.php.
  3. Now you should be able to log in by navigating to your new URL. In our case, it’s domain/new-secret-login-file.php.

Note: If any HTTP/HTTPS requests to the /wp-login.php, or /wp-admin, directories will lead visitors to a 404 not-found page.

Third Method (Protect wp-login.php With a Cookie and .htaccess):

  1. Add this code into your .htaccess file in the root folder.
    <IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteCond %{HTTP_COOKIE} !^.*wp\-connect=2917998723.*$ [NC]
    RewriteRule wp-login.php - [F]
    </IfModule>
  2. Create a new login page for cookie like new-secret-login-page.php and ad below code:
    <?php
    setcookie("wp-connect", 2917998723);
    header("Location: wp-login.php");

     

Note: Please remember, Admins need to first go to domain/wp-connect.php to access wp-login.php


   
Quote