Tutorial: Gravity Forms Automatically Login User After Registration

Wordpress Tutorial: Gravity Forms Automatically login user after registration

In this tutorial we are going to show you how to make Gravity Forms Automatically login user after they register for an account. The default behavior in WordPress after registration is to require the user to login with the account information that they just created. This login requirement can be an annoying and extra step for the user and isn’t necessary.

In order for this to work it requires the User Registration Add-On  for Gravity Forms. Assuming this add-on is installed and activated, go ahead and navigate to your current themes functions.php file where we will be adding our code.

Gravity Forms Automatically login user after registration

In order to get this function to work all you have to do is add the following code snippet to your current theme’s functions.php file. As usually, if you don’t have a child theme installed on your website we highly recommend you do that and paste it in the child themes functions.php. If you don’t have a child theme and would like to create one, here is a tutorial how to create a WordPress child theme.

				
					add_action( 'gform_user_registered', 'wpc_gravity_registration_autologin',  10, 4 );
/**
 * Auto login after registration.
 */
function wpc_gravity_registration_autologin( $user_id, $user_config, $entry, $password ) {
	$user = get_userdata( $user_id );
	$user_login = $user->user_login;
	$user_password = $password;
       $user->set_role(get_option('default_role', 'subscriber'));

    wp_signon( array(
		'user_login' => $user_login,
		'user_password' =>  $user_password,
		'remember' => false

    ) );
}
				
			

That’s all there is to it! You just made Gravity Forms Automatically login user after they have filled out your registration form using the User Registration Add-On. 

We have plenty of other great Gravity Forms WordPress tutorials that you can check out here: Gravity Forms WordPress Tutorials. One of our recent tutorials we show you how to Create a Unique ID for Gravity Forms Entries.

Redirect User After Login

As an extra bonus we thought we would include this little hint as well just in case you’re new to Gravity Forms. Now that you have Gravity Forms Automatically login users after registration, what if you want to have them redirect to a specific page afterwards?

To configure the URL to which the user should be redirected to, you will simply need to go into the  Forms Settings and under Confirmations and Confirmations Type simply click Page and choose the desired page.

Gravity Forms Redirect After Login

Table of Contents

Looking for more?

Here are some other articles that we think you will be interested in!

Screenshot of the Elementor page builder interface, with a drag-and-drop sidebar on the left and a web page preview on the right. A logo sits centerstage, set against a pink and purple gradient—perfect for adding PHP Code to Elementor projects.

How To Add PHP Code to Elementor

In this tutorial, we are going to show you how to easily add PHP Code to any Elementor page by creating a simple shortcode and adding it to your functions.php

Screenshot showing a webpage with food listings and a pop-up form titled Listing Settings, where a restaurant listing is being edited. Three food-related cards are visible, displayed in a layout created with WPBakery Visual Composer.

Create A WPBakery Visual Composer Add-On

Learn how easy it is to create a WPBakery Visual Composer Add-on element that you can use for almost any application! This can come in handy when you’re building a website for a client that isn’t so tech savy, but would like to be able to make some changes on their own in the future. Click the link to get started: