wp_redirect_admin_locations

Redirects a variety of shorthand URLs to the admin.

Description

wp_redirect_admin_locations(); 

If a user visits example.com/admin, they'll be redirected to /wp-admin. Visiting /login redirects to /wp-login.php, and so on.


Usage

  1. if ( !function_exists( 'wp_redirect_admin_locations' ) ) { 
  2. require_once ABSPATH . WPINC . '/canonical.php'; 
  3.  
  4.  
  5. // NOTICE! Understand what this does before running. 
  6. $result = wp_redirect_admin_locations(); 
  7.  

Defined (1)

The function is defined in the following location(s).

/wp-includes/canonical.php  
  1. function wp_redirect_admin_locations() { 
  2. global $wp_rewrite; 
  3. if ( ! ( is_404() && $wp_rewrite->using_permalinks() ) ) 
  4. return; 
  5.  
  6. $admins = array( 
  7. home_url( 'wp-admin', 'relative' ),  
  8. home_url( 'dashboard', 'relative' ),  
  9. home_url( 'admin', 'relative' ),  
  10. site_url( 'dashboard', 'relative' ),  
  11. site_url( 'admin', 'relative' ),  
  12. ); 
  13. if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $admins ) ) { 
  14. exit; 
  15.  
  16. $logins = array( 
  17. home_url( 'wp-login.php', 'relative' ),  
  18. home_url( 'login', 'relative' ),  
  19. site_url( 'login', 'relative' ),  
  20. ); 
  21. if ( in_array( untrailingslashit( $_SERVER['REQUEST_URI'] ), $logins ) ) { 
  22. exit;