wp_redirect_admin_locations() WordPress Function

The wp_redirect_admin_locations() function allows you to redirect the user to a different URL when they try to access the WordPress admin area. This can be useful if you want to restrict access to the admin area to certain users or if you want to redirect the user to a specific page after they login.

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.


Top ↑

Source

File: wp-includes/canonical.php

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


Top ↑

Changelog

Changelog
VersionDescription
3.4.0Introduced.

The content displayed on this page has been created in part by processing WordPress source code files which are made available under the GPLv2 (or a later version) license by theĀ Free Software Foundation. In addition to this, the content includes user-written examples and information. All material is subject to review and curation by the WPPaste.com community.