How to Auto Login After Registration in WordPress with core php

Add on function.php for Auto login after register and redirect to a home page. varified this code

function auto_login_new_user( $user_id ) {
$user = get_user_by( 'id', $user_id );
do_action( 'wp_login', $user->user_login );//`[Codex Ref.][1]
wp_redirect( home_url() ); // You can change home_url() to the specific URL,such as "wp_redirect( '' )";
add_action( 'user_register', 'auto_login_new_user' );

Leave a Reply

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