2

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.

1

1 Answer 1

1

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).

2
  • That didnt seem to work.
    – Shae
    Commented Feb 8, 2014 at 1:38
  • actually there must be something preventing it from working on the site i tried. I did it on another and it worked
    – Shae
    Commented Feb 8, 2014 at 1:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.