Customizing wp-admin page url

Hi all,

I’m trying to change the url http://example-site.dev/wp/wp-admin/ into http://example-site.dev/custom-admin.

I have tried the following:

  • Rename that /wp/wp-admin folder into /custom-admin, then finding & replacing it all, but it has proven to lose css styles and I do not wish to do alter the /wp core files
  • Adding the blocks of code from codex forums on this topic (this link takes you to one of the many pages that show the same code http://help4cms.com/change-admin-url-without-plugin/ )
  • Using WPS Hide Login Plugin

…and none of them work.
The last straw was when I tested that same plugin and it works fine on a standard wordpress site because it adheres to the standard file structure.

I am assuming there should be a bedrock way of doing this, does anyone know?

Thanks in advance

Could I ask why you want to do this?

For branding purposes & security reasons.

Hi there,

Did you find out how to achieve it?

Thanks;

Not to bump too hard - but wondering if there is any solution to the above for Bedrock/Roots users?

+1 to this. Curious to know possible to change wp-admin url without breaking anything.

iThemes Security plugin has a built-in feature for this! Can’t remember if you can also get rid of the /wp/ though…

Hello, guys. Struggling with this as well. Has anyone found the answer for it?

That’s obscurity, not security. I’m not saying obscurity is bad, but it’s not the same thing as security.

obscurity IS security. The fact that every single bot knows what the wp login url is is a security issue at this point. His point is valid. It should be a part of standard practice to be able to change the default url for login to WP sites.

This is a feature that Roots really needs to look into. Using alternate plugins is not an ideal solution at all.

Still no suggestions for solution here?

We hold the opinion that this isn’t something that should be modified. There’s several ways to lock down the wp-admin or the login page that don’t involve trying to rename the wp-admin directory.

I’d suggest you raise these concerns with WordPress core — I’m certain there’s at least one discussion about this on WordPress Trac

I recommend iThemes for the ability to hide backend and much more.

But also worth noting that if you used Valet or Valet-plus for local dev you may experience issues reaching the URL while iThemes was active.

Until recently I just deactivated it, but I figured out what was wrong and the latest Valet should work and for valet-plus you could patch it with the PR I created for them
Fix bedrockvaletdriver by EHLOVader · Pull Request #1289 · laravel/valet · GitHub or Fix bedrockvaletdriver by EHLOVader · Pull Request #612 · weprovide/valet-plus · GitHub

the additional /wp/ can be handled with an .htaccess rewrite or nginx config I’m sure

I had this from before, but I still usually forget to add it and just use wp/hidden-admin (no not my real path, I’m not telling you that)

<IfModule mod_rewrite.c>
# Enable the hide backend feature - Security > Settings > Hide Login Area > Hide Backend
        RewriteRule ^(/wp/)?hidden-admin/?$ /wp/wp-login.php [QSA,L]
        RewriteRule ^(/wp/)?wp-register-php/?$ /wplogin?action=register [QSA,L]
</IfModule>

Sorry, still no solution? :grimacing:

You can do it like this:

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class CustomAdminProvider extends ServiceProvider
{

    private $_admin = 'custom-admin';
    private $_login = 'custom-login';


    /**
     * Register services.
     *
     * @return void
     */
    public function register(): void
    {
        remove_action( 'template_redirect', 'wp_redirect_admin_locations', 1000 );
        add_action( 'template_redirect', [$this, 'wp_redirect_admin_locations'], 999 );
    }

    /**
     * Bootstrap services.
     *
     * @return void
     */
    public function boot(): void
    {
    }

    public function wp_redirect_admin_locations() {
        global $wp_rewrite;
        if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) {
            return;
        }
    
        $admins = array(
            home_url( $this->_admin, 'relative' ),
            site_url( $this->_admin, 'relative' ),
        );
    
        if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins, true ) ) {
            wp_redirect( admin_url() );
            exit;
        }
        
        
        $logins = array(
            home_url( $this->_login, 'relative' ),
            site_url( $this->_login, 'relative' ),
        );
    
        if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins, true ) ) {
            wp_redirect( wp_login_url() );
            exit;
        }
    }
}

ready


Also if you use bedrock

You can also change the name of the wp folder from url.test/wp/…

Example: If you use bedrock we want to switch from wp to asd

  1. Change in config/application.php

de

if (!defined('ABSPATH')) {
    define('ABSPATH', $webroot_dir . '/wp/');
}

a

if (!defined('ABSPATH')) {
    define('ABSPATH', $webroot_dir . '/asd/');
}
  1. Change in /web/index.php
<?php
/**
 * WordPress View Bootstrapper
 */
define('WP_USE_THEMES', true);
require __DIR__ . '/wp/wp-blog-header.php';

a

<?php
/**
 * WordPress View Bootstrapper
 */
define('WP_USE_THEMES', true);
require __DIR__ . '/asd/wp-blog-header.php';

  1. Change in /composer.json
...
"wordpress-install-dir": "public_html/wp"
...

to

...
"wordpress-install-dir": "public_html/asd"
...

PS: Sorry for my English, I used gtranslate