Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rename WordPress admin URL wp-admin

I want to rename the admin URL 'wp-admin' to e.g. 'admin'. I set a rewrite rule in the .htaccess to acces the admin login: RewriteRule ^admin wp-admin [NC,L]

That works but I can still use /wp-admin. So I have to tell Wordpress that 'admin' is the new URL.

Can anyone help?

like image 482
user3684098 Avatar asked Oct 27 '25 14:10

user3684098


2 Answers

Solution without plugins:

Edit the .htaccess and add the code below between the IfModule mod_rewrite.c tags:

RewriteRule ^admin$ /wp-login.php [NC,L] 
RewriteRule ^admin/(.*) wp-admin/$1?%{QUERY_STRING} [L]

Also edit the wp-config.php and add:

define('WP_ADMIN_DIR', 'admin');
define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);

Edit the functions.php file from your theme and add:

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);
}

And that's it! Enjoy

like image 160
Clarissa Holz Avatar answered Oct 30 '25 05:10

Clarissa Holz


A better way would be to install the iThemes Security plugin (formerly Better WP Security).

Or follow this easy 5-step guide on changing wp-admin.

like image 30
sheraz Avatar answered Oct 30 '25 04:10

sheraz