In last post we shared the trick to hide WordPress login URL using .htaccess file. This tutorial is bit different from the previous tutorial. In last tutorial we just redirected /login to /wp-login.php, but now we will change the WordPress admin URL /wp-admin/ to /admin-panel/. It’s not the redirection, we’ll completely change the default admin slug to admin-panel.
This is a must use trick if you’re working on a client website. In this way, it’d hard for people to identify if it’s a WordPress site. We can also restrict the access to /wp-admin/ URL. Let’s get started with the first stuff:
Hide WordPress Admin URL
[alert style=”red”]According to user feedback, this snippet doesn’t work anymore. Only use it if you know what you’re doing.[/alert]
Add following snippet to your WordPress’ wp-config.php file:
define('WP_ADMIN_DIR', 'admin-panel'); define( 'ADMIN_COOKIE_PATH', SITECOOKIEPATH . WP_ADMIN_DIR);
Now, add following snippet to your current theme’s functions.php file:
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); }
Finally, add following snippet to your .htaccess file:
RewriteRule ^admin-panel/(.*) wp-admin/$1?%{QUERY_STRING} [L]
Now your admin URL will be like: http://www.yoursite.com/admin-panel/
Restrict wp-admin URLs:
The following code will redirect all /wp-admin/ URL requests to your 404.php error page. Add it on your theme’s functions.php file:
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' ); } } }
Hello, good article but..not function. I have a “not found” error. Can you help me please? Thank’s
Try all the steps again and it should work. What’s the address of your site?
Hi it did not work for me as well… something is wrong with your steps
Please put your website URL when you answer these tricks so I could check your site to see what’s not working :)
For .htaccess, should be:
RewriteRule ^admin-panel(.*) wp-admin/$1?%{QUERY_STRING} [L]
remove / from ^admin-panel/(.*)
:)
Thanks,
when im opening my wp-admin it is opening the login page but an error is howing under the password
“Warning: Cannot modify header information – headers already sent by (output started at /home/madnessf/public_html/wp-login.php:61) in /home/madnessf/public_html/wp-includes/pluggable.php on line 1121”
so can u please tell me hoe it can completely be moved to 404.php page
Good day Hardeep Asrani,
I’m having problem with the code you share.
Here is the link of my website where i put you code http://www.101pinoy.info/
And also i notice that when i use the websitelink/wp-login.php i can still open my dashboard
Thanks in advance :)
Avoid sharing the wrong information! That code will never work!
It worked when I wrote the article, but now it’s not working. I guess I need to put a “Not Working” or something like that tag on this article. And the fact that I’m approving your comment proves that it worked back then :)
Cool tricks!
So it worked for you?
Nice and Very Helpful Tutorial!
Hello there, i just found this and I was dissapointed that it stopped working. But i managed to get it working again, by accident :)
You just have to add this line in .htaccess:
RewriteRule ^admin/?$ /wp-login.php [QSA,L]
It worked for me on 4.3.1 version. Good luck!
its work for me thanks
Nice trick. But you know that wordpress is always updating.
Once it updated, those wp-config.php and functions.php would be rewrited by the new one.
So it will be better to do that trick in theme or plugin level.
IMHO.
WuoOooo Great
Just done and working well WordPress 4.8
Thank your tutorial