How would I create a wordpress function that will redirect a user to myurl.com/wp-admin if they type in myurl.com/admin?
I would like to have this as a wordpress function.
Hook into template_redirect
, inspect the request URI, and redirect to the return value of admin_url()
.
add_action( 'template_redirect', function()
{
$request = untrailingslashit( strtolower( $_SERVER['REQUEST_URI'] ) );
if ( 'admin' === $request )
{
wp_redirect( admin_url() );
exit;
}
});
Note: always use admin_url()
and the other built-in URL functions, because they will take care of the proper scheme (https
or http
).