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
- Change in config/application.php
de
if (!defined('ABSPATH')) {
define('ABSPATH', $webroot_dir . '/wp/');
}
a
if (!defined('ABSPATH')) {
define('ABSPATH', $webroot_dir . '/asd/');
}
- 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';
- 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