Mobile-Menu iFuturz Infoweb Inc. Contact Portfolio

16

Jul

Change admin url in wordpress

Change admin url in wordpress

Posted On : July 16, 2013

| 1 Comment

For security reasons, we need to change Admin Login URL , from “yourdomain.com/wp-admin” to “yourdomain.com/xyz”

For completing this task, we can either use plugin like “HC Custom WP-Admin URL” or “Lockdown WP Admin”.

But the same task we can do by simple coding in 1-2 files.

Code 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//Add below code in theme function.php file
add_filter('site_url', 'mywpadmin_filter', 10, 3);
 
function mywpadmin_filter($url, $path, $orig_scheme) {
    $old = array("/(wp-admin)/", "/(wp-login\.php)/");
    $new = array(WP_ADMIN_DIR, "my-login");
    return preg_replace($old, $new, $url, 1);
}
 
add_action('login_form', 'redirect_wp_admin');
 
function redirect_wp_admin() {
    $redirect_to = $_SERVER['REQUEST_URI'];
    if (count($_REQUEST) > 0 && array_key_exists('redirect_to', $_REQUEST)) {
        $redirect_to = $_REQUEST['redirect_to'];
        $check_wp_admin = stristr($redirect_to, 'wp-admin');
        if ($check_wp_admin) {
            wp_safe_redirect('404.php');
        }
        if (strpos($_SERVER['REQUEST_URI'], "wp-login.php") !== false) {
            wp_safe_redirect('404.php');
        }
    } elseif (strpos($redirect_to, "wp-login.php") !== false) {
        wp_safe_redirect('404.php');
    }
}

Code 2:

1
2
3
//Add below code in .htaccess file
RewriteRule ^mywpadmin/(.*) wp-admin/$1?%{QUERY_STRING} [L]
RewriteRule ^my-login$ wp-login.php [L]

Code 3:

1
2
3
//Add below code in wp-config.php file
define('WP_ADMIN_DIR', 'mywpadmin');
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);

Now, your admin url will be : yourdomain.com/mywpadmin/

  • Tags:

Comment

Posts

  • Nice post. I was checking this blog and I’m inspired!

    Very helpful information as I was seeking it for a long time.
    Thank you and good luck.

    romi