On this page
wp_redirect_admin_locations()
Redirects a variety of shorthand URLs to the admin.
Description
If a user visits example.com/admin, they’ll be redirected to /wp-admin.
Visiting /login redirects to /wp-login.php, and so on.
Source
File: wp-includes/canonical.php. View all references
function wp_redirect_admin_locations() {
global $wp_rewrite;
if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) {
return;
}
$admins = array(
home_url( 'wp-admin', 'relative' ),
home_url( 'dashboard', 'relative' ),
home_url( 'admin', 'relative' ),
site_url( 'dashboard', 'relative' ),
site_url( 'admin', 'relative' ),
);
if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins, true ) ) {
wp_redirect( admin_url() );
exit;
}
$logins = array(
home_url( 'wp-login.php', 'relative' ),
home_url( 'login', 'relative' ),
site_url( 'login', 'relative' ),
);
if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins, true ) ) {
wp_redirect( wp_login_url() );
exit;
}
}
Related
Uses
| Uses | Description |
|---|---|
| untrailingslashit() wp-includes/formatting.php | Removes trailing forward slashes and backslashes if they exist. |
| wp_redirect() wp-includes/pluggable.php | Redirects to another page. |
| wp_login_url() wp-includes/general-template.php | Retrieves the login URL. |
| is_404() wp-includes/query.php | Determines whether the query has resulted in a 404 (returns no results). |
| site_url() wp-includes/link-template.php | Retrieves the URL for the current site where WordPress application files (e.g. wp-blog-header.php or the wp-admin/ folder) are accessible. |
| WP_Rewrite::using_permalinks() wp-includes/class-wp-rewrite.php | Determines whether permalinks are being used. |
| admin_url() wp-includes/link-template.php | Retrieves the URL to the admin area for the current site. |
| home_url() wp-includes/link-template.php | Retrieves the URL for the current site where the front end is accessible. |
Changelog
| Version | Description |
|---|---|
| 3.4.0 | Introduced. |
© 2003–2022 WordPress Foundation
Licensed under the GNU GPLv2+ License.
https://developer.wordpress.org/reference/functions/wp_redirect_admin_locations