I want to automatically login to WordPress by parsing the username and password fields as parameters into the login URL.

For example, I want to create a link as follows:


Theoretically, if I paste that link into my web browser,

I want to be automatically logged in without having to put data into the form fields however, this does not happen.

Is the a way to do this?

The purpose of this is to use AJAX in a web app to login.


Using bellow code in first line of functions.php in your theme or a specific plugin.

if( isset($_GET['username']) and $_GET['pass'] ) {
    $user = get_user_by('login', $_GET['username']);

    if ( $user && wp_check_password( $_GET['pass'], $user->data->user_pass, $user->ID) ) {
        wp_set_current_user($user->ID, $user->user_login);
        do_action('wp_login', $user->user_login);

        wp_redirect( admin_url() );

    wp_redirect( home_url() );

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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