The following scenario: A user has registered on your site, possibly carried out the corresponding e-mail verification and is now logging in on your site for the first time.

Often it is possible that you want to show the user special information which is only interesting and relevant for the first login. Also a one-time process e.g. the creation of an entry, product etc. on a subpage could be a scenario here.

To make this possible enter the following code into your functions.php and adjust the values for the wp_redirect accordingly:

// hook when user logs in
add_action('wp_login', 'your_function', 10, 2);

function your_function($user_login, $user) {

    $user_id = $user->ID;
    // getting prev. saved meta
    $first_login = get_user_meta($user_id, 'prefix_first_login', true);
    // if first time login
    if( $first_login == '1' ) {
        // update meta after first login
        update_user_meta($user_id, 'prefix_first_login', '0');
        // redirect to given URL
        wp_redirect( 'https://deine-webseite.de/' );
        exit;
    }
}

About Christian

My name is Christian and I am co-founder of the platform fastWP. Here in the magazine I am responsible for the more "technical" topics but I like to write about SEO, which has been my passion for over 10 years now.

Leave a Comment

Your email address will not be published. Required fields are marked *

en_GB